gabriel / MPMessagePack

MessagePack implementation for Objective-C / msgpack.org[Objective-C]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NSNumber boolean detection not working

connectdotz opened this issue · comments

in MPMessagePackWriter: line 59:

- (BOOL)writeNumber:(NSNumber *)number context:(cmp_ctx_t *)context error:(NSError * __autoreleasing *)error {
    if (strcmp([number objCType], @encode(BOOL)) == 0) {
        cmp_write_bool(context, number.boolValue);
        return YES;
     }

[number objCType] returns 'c' and @encoded(BOOL) returns 'B', therefore a boolean nsnumber is never written out as boolean.

Apple's NSNumber documented:

Special Considerations
The returned type does not necessarily match the method the number object was created with.

using objCType might not be the best way to detect boolean...

here is my env: xcode 6.1.1 ios8.1 SDK

This works in the simulator:

 if (CFGetTypeID((CFNumberRef)number) == CFBooleanGetTypeID()) {
    cmp_write_bool(context, number.boolValue);
    return YES;
}

Fixed in c8aeebf

I ended up checking if it pointer equals kCFBooleanTrue kCFBooleanFalse which is how NSJSONSerialization works correctly.