Comparison of NSCFString and NSCFBoolean

I am using SBJsonParser to parse JSON. The input can be 0 or a string (for example, a829d901093), and if it is zero, NSCFBoolean is returned if its string is NSCFString. How can I find out which one is returned? Thanks!

+4
source share
1 answer

Calling for their internal duty free names makes this confusing. If you name them NSNumber and NSString (as indicated in the documentation), then the answer will be clear:

 if ([value isKindOfClass:[NSNumber class]]) { ... } 

EDIT : @Magnus indicates that it is not obvious that a NSCFBoolean isa NSNumber to watch them. It's true. This is very obvious to me, because I know a system like Core Foundation, and I know what the classes of paid free bridges mean and how they are implemented (this is one of the coolest tricks in all Cocoa IMOs). But what if you did not know this? This is still not a problem.

  • In the debugger, scroll through the list of variables and expand the variable you care about. His first "member" will be his superclass. Expand Continue until you find the class that you know.

  • Alternatively, you can go over superclasses with NSStringFromClass([object superclass]) . Continue to superclass to the number of levels you want to test.

+8
source

Source: https://habr.com/ru/post/1343105/


All Articles