- 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.
推薦閱讀
- 深入淺出Java虛擬機:JVM原理與實戰
- PHP程序設計(慕課版)
- 編程珠璣(續)
- Apache Karaf Cookbook
- 差分進化算法及其高維多目標優化應用
- JavaScript by Example
- Backbone.js Blueprints
- Flux Architecture
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- R用戶Python學習指南:數據科學方法
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- QGIS 2 Cookbook
- Java編程從入門到精通
- Extending Unity with Editor Scripting
- Appcelerator Titanium:Patterns and Best Practices