Numeric types don't automatically bridge to NSNumber in pure Swift on Ubuntu Linux?

佐手、 提交于 2019-12-21 19:41:50

问题


On MacOS, if you do:

import Foundation
let x = Int32(1) as? NSNumber

x is non-nil.

On Ubuntu Linux, if you do the same (even with Swift 3.1.1), x is nil.

Am I doing something wrong, or is this just a fact of a lack of bridging of numeric types to NSNumber with the Foundation with Swift on Ubuntu/Linux?

See also Is it possible to replicate Swifts automatic numeric value bridging to Foundation (NSNumber) for (U)Int8/16/32/64 types? and https://github.com/SwiftyJSON/SwiftyJSON/issues/745


回答1:


There is no automatic bridging to NSNumber on Linux. Source: 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.



来源:https://stackoverflow.com/questions/43828307/numeric-types-dont-automatically-bridge-to-nsnumber-in-pure-swift-on-ubuntu-lin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!