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

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.

主站蜘蛛池模板: 松原市| 华池县| 区。| 隆安县| 祁门县| 扎兰屯市| 义马市| 安庆市| 麻栗坡县| 嵊州市| 屯门区| 贵定县| 余江县| 天津市| 福州市| 靖边县| 辽源市| 常山县| 云梦县| 股票| 潍坊市| 平安县| 遂宁市| 榆社县| 马公市| 大余县| 油尖旺区| 正定县| 葫芦岛市| 嘉鱼县| 遂宁市| 镇雄县| 西和县| 黄平县| 沙雅县| 迁西县| 思南县| 龙门县| 赫章县| 金平| 新河县|