Danger: @true and @false aren't considered booleans
Danger: @true and @false aren't considered booleans
- Subject: Danger: @true and @false aren't considered booleans
- From: Jens Alfke <email@hidden>
- Date: Sat, 18 Aug 2012 20:33:54 -0700
Warning to people 'modernizing' their syntax to use the new Obj-C literals: I've run into a serious problem with @true and @false. The runtime objects these create are _not_ the same as those created by [NSNumber numberWithBool] or the CF constants kCFBooleanTrue and kCFBooleanFalse. They're created with the type-encoding "i" (integer) instead of "c" (char).
The most serious problem — and the one that caused me to discover this — comes with NSJSONSerialization. @true and @false don't encode to JSON as "true" and "false", but "0" and "1". This can really screw up things that try to parse the JSON your code generates. In my case, some well-tested CouchDB client code started to fail after I modernized the syntax, and I traced the problem down to this. Apparently CouchDB was unhappy about some boolean parameter values being "1" instead of "true" and returned an HTTP 500 status.
I've filed a bug report against Clang, which has the distinct advantage that you can actually read my bug report (imagine that!) and see my test case.
http://llvm.org/bugs/show_bug.cgi?id=13640
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden