- 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.
推薦閱讀
- Python量化投資指南:基礎(chǔ)、數(shù)據(jù)與實(shí)戰(zhàn)
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- OpenStack Orchestration
- RabbitMQ Essentials
- Multithreading in C# 5.0 Cookbook
- 交互式程序設(shè)計(jì)(第2版)
- Visual Basic 程序設(shè)計(jì)實(shí)踐教程
- PostgreSQL 12 High Availability Cookbook
- SaaS攻略:入門、實(shí)戰(zhàn)與進(jìn)階
- HTML5程序設(shè)計(jì)基礎(chǔ)教程
- MySQL核心技術(shù)與最佳實(shí)踐
- Three.js Essentials
- Visual C++ 開發(fā)從入門到精通
- LiveCode Mobile Development Hotshot
- 匯編語(yǔ)言程序設(shè)計(jì)教程