4

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

Community
  • 1
  • 1
Chris Prince
  • 7,288
  • 2
  • 48
  • 66

1 Answers1

2

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.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    And it looks like we'll have this in Swift 4. See https://github.com/apple/swift-evolution/commit/101d0f6c20fc9d8c3139cc84ac54990790809b2a – Chris Prince May 08 '17 at 01:07