[swift-evolution] Swift's Optional Int as NSNumber in Objective-C

John McCall rjmccall at apple.com
Fri May 12 11:56:43 CDT 2017

> On May 12, 2017, at 10:10 AM, Yarik Arsenkin via swift-evolution <swift-evolution at swift.org> wrote:
> Hi,
> does anyone know if there is a reason why bridging of the Swift’s `Int?` type doesn’t work for Objective-C? I mean, it could be exposed as an `NSNumber` with nullable attribute, no?

I assume you're talking about the type restrictions on exporting Swift functions as @objc.  We have the technical ability to bridge any Swift value to Objective-C as an opaque object, but that wouldn't actually produce meaningful APIs on the ObjC side; we have to have some sort of tighter policy than that.  Today, that policy is to allow export when there's an obvious, idiomatic analogue in Objective-C.  Exporting Int? as an optional NSNumber does not feel obvious and idiomatic when we would export Int as NSInteger.  It feels like reaching for an arbitrary solution.


More information about the swift-evolution mailing list