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

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.

主站蜘蛛池模板: 淄博市| 拜泉县| 临猗县| 岳普湖县| 和田市| 于田县| 灵川县| 平原县| 循化| 尉氏县| 溧阳市| 嘉祥县| 保德县| 武宁县| 富民县| 上饶市| 张家川| 武冈市| 吉木乃县| 德庆县| 萨嘎县| 阜宁县| 洪江市| 白山市| 嘉义市| 讷河市| 崇义县| 鹤山市| 宁强县| 河津市| 安吉县| 新野县| 三亚市| 广灵县| 兴安盟| 饶河县| 邛崃市| 墨脱县| 江永县| 山阳县| 错那县|