NSNumber boolean detection not working
connectdotz opened this issue · comments
ConnectDotz commented
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...
ConnectDotz commented
here is my env: xcode 6.1.1 ios8.1 SDK
roryobryan commented
This works in the simulator:
if (CFGetTypeID((CFNumberRef)number) == CFBooleanGetTypeID()) {
cmp_write_bool(context, number.boolValue);
return YES;
}
Gabriel Handford commented
Fixed in c8aeebf
I ended up checking if it pointer equals kCFBooleanTrue kCFBooleanFalse which is how NSJSONSerialization works correctly.