- 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.
推薦閱讀
- Advanced Splunk
- The DevOps 2.3 Toolkit
- Advanced Machine Learning with Python
- Java完全自學教程
- Building a RESTful Web Service with Spring
- 編程卓越之道(卷3):軟件工程化
- Java 9 Programming Blueprints
- PLC編程及應用實戰
- Android 應用案例開發大全(第3版)
- MATLAB for Machine Learning
- Unity Character Animation with Mecanim
- Delphi開發典型模塊大全(修訂版)
- Building Slack Bots
- JavaScript編程精解(原書第2版)
- UI動效設計從入門到精通