[swift-users] Foundation on Linux `CFBooleanGetTypeID`/`CFGetTypeID`

Tony Parker anthony.parker at apple.com
Tue May 24 14:52:30 CDT 2016


> On May 24, 2016, at 12:49 PM, Jens Alfke <jens at mooseyard.com> wrote:
> 
> 
>> On May 24, 2016, at 11:03 AM, Tony Parker <anthony.parker at apple.com <mailto:anthony.parker at apple.com>> wrote:
>> 
>> Why not use `func boolValue` instead, if you need a true/false answer?
> 
> I don’t remember the original code snippet, but there are cases where you need to know what type of number is stored in an NSNumber. An example is encoding to JSON, where a boolean value should be written as “true” or “false”, not “1” or “0”.
> 
> —Jens

Fair enough, and we do use this trick in NSJSONSerialization(.m).

One other possibility is using the objCType property on NSNumber’s superclass NSValue to check. I haven’t seen how much of this is implemented in corelibs-foundation yet. We did redefine Boolean to _Bool in Swift CF, so we’ll have to see if that accidentally resulted in a runtime difference between platforms here that we didn’t consider.

- Tony

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160524/c6ea738f/attachment.html>


More information about the swift-users mailing list