在MacOS上,如果你这样做:
import Foundation
let x = Int32(1) as? NSNumber
x是非零的.
在Ubuntu Linux上,如果你这样做(即使使用Swift 3.1.1),x也是零.
我做错了什么,或者这只是在Ubuntu / Linux上使用Swift的基础与NSNumber缺少数字类型的事实?
另见Is it possible to replicate Swifts automatic numeric value bridging to Foundation (NSNumber) for (U)Int8/16/32/64 types?
和https://github.com/SwiftyJSON/SwiftyJSON/issues/745
最佳答案 在Linux上没有自动桥接NSNumber.资源:
NSNumber bridging and Numeric types:
Considerations for Linux platforms
We do not have bridging on Linux so the
as?
cast is less important; but if it were to have bridging this would be the desired functionality.