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

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.

主站蜘蛛池模板: 随州市| 苗栗县| 阿勒泰市| 左贡县| 新安县| 内丘县| 邓州市| 定西市| 治县。| 玛曲县| 丰镇市| 平度市| 吴旗县| 贵溪市| 织金县| 西藏| 深圳市| 五指山市| 宜川县| 西充县| 凤冈县| 镇安县| 兰坪| 深水埗区| 屏东县| 温宿县| 当雄县| 水城县| 昆山市| 桐庐县| 铁岭县| 闽侯县| 锡林郭勒盟| 五莲县| 长春市| 玛曲县| 沭阳县| 东莞市| 德兴市| 中宁县| 庆元县|