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

Ben Rimmington me at benrimmington.com
Mon May 22 08:07:36 CDT 2017

> On 20 May 2017, at 19:58, Philippe Hausler wrote:
>> On May 20, 2017, at 12:25 AM, David Waite wrote:
>> I believe behavior depends on whether the NSNumber is the objc type or swift subtype, and whether you call the NSNumber.intValue or use Int.init?(exactly: NSNumber).
> That part of the behavior is no longer the case. The bridge only transacts upon one number type (to leverage tagged pointers) and the subclass was removed (since it caused some gnarly inconsistencies)

The subclass `_SwiftTypePreservingNSNumber` still exists:


Maybe the file isn't compiled anymore due to your pull requests:


You mentioned tagged pointers. My understanding is that:

* `OBJC_TAG_NSNumber` doesn't attempt to store a `float` or `double` in the 60-bit payload;
* `OBJC_TAG_NSDate` is used only if bits 0...3 of the `NSTimeInterval` (aka `double`) are zero.


How often is an NSDate (with "sub-millisecond precision") created as a tagged pointer?

-- Ben

More information about the swift-evolution mailing list