I am using SBJsonParser to parse JSON. An input can be 0 or a string (ex. a829d901093), and if it's zero, NSCFBoolean is returned, if its string NSCFString is returned. How can I tell which one is returned? Thanks!
Calling these by their internal toll-free names is what makes this confusing. If you call them NSNumber
and NSString
(as they are listed in the documentation), then the answer is clear:
if ([value isKindOfClass:[NSNumber class]]) { ... }
EDIT: @Magnus points out that it isn't obvious that a NSCFBoolean
isa NSNumber
in order to look them up. That's true. To me it's very obvious because I know the Core Foundation type system and I know what the toll free bridge classes mean and how they're implemented (it's one of the coolest tricks in all of Cocoa IMO). But what if you didn't know those things? It's still no problem.
In the debugger, look in the variable list and expand the variable you care about. Its first "member" will be it superclass. Expand. Continue until you find a class you know.
Alternately, you can walk the superclasses using NSStringFromClass([object superclass])
. Keep tacking superclass
on for as many levels as you'd like to check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With