> On May 24, 2016, at 12:49 PM, Jens Alfke <[email protected]> wrote:
> 
> 
>> On May 24, 2016, at 11:03 AM, Tony Parker <[email protected] 
>> <mailto:[email protected]>> 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

_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to