官术网_书友最值得收藏!

Improved NSNumber

With earlier versions of Swift, behavior of NSNumber might be unexpected and casting to Uint8 might result in absurd results:

let number1 = NSNumber(value: 1000)
let number1ConvertedToUInt = number1 as? UInt8

In this scenario, logically, the value inside number1ConvertedToUInt should be nil, but this was not the case and the value would be 1000% 255, that is, 232 instead. This is because the maximum value that a UInt can hold is 255. Fortunately, this behavior has been resolved in Swift 4 and now if you execute the same code in Swift 4, you should expect the value of number1ConvertedToUInt to be nil.

主站蜘蛛池模板: 洛南县| 台江县| 白城市| 崇文区| 尼木县| 龙岩市| 庆元县| 特克斯县| 巫溪县| 芜湖县| 巧家县| 阿坝| 铜陵市| 长沙县| 绥德县| 额尔古纳市| 桃江县| 长子县| 潢川县| 广元市| 白银市| 长春市| 东安县| 儋州市| 南澳县| 黄浦区| 芜湖县| 法库县| 阜康市| 七台河市| 绥滨县| 遵化市| 丹寨县| 吉林省| 图木舒克市| 临沧市| 陇川县| 安远县| 惠来县| 南开区| 新化县|