- Reactive Programming with Swift 4
- Navdeep Singh
- 104字
- 2021-06-24 18:58:01
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.
推薦閱讀
- Testing with JUnit
- 編程珠璣(續)
- 差分進化算法及其高維多目標優化應用
- Amazon S3 Cookbook
- 用戶體驗增長:數字化·智能化·綠色化
- Mastering Unity 2D Game Development(Second Edition)
- Python High Performance Programming
- C++反匯編與逆向分析技術揭秘(第2版)
- 小型編譯器設計實踐
- SciPy Recipes
- SpringBoot從零開始學(視頻教學版)
- Go Systems Programming
- Managing Windows Servers with Chef
- 代碼整潔之道:程序員的職業素養
- iOS程序員面試筆試真題與解析