i am actually debugging my iOS Application: i want to test if a variable is null or not:
Stupid question huh !
if (var !=nil) { doSomeWork ; }
So if the variable var is equal to nil and we want to print this result in the debugger area we will have something like that:
2012-10-12 21:33:01.553 Application’s Name [892:13d03] (null)
This is cool, but indeed when i try to print the variable content in the debugger area, it has been showing :
2012-10-12 21:33:01.553 Application’s Name [892:13d03] < null >
Can you tell me guys what is the difference between this two kinds of null, and how can i test if the second one is equal to nil.
Thanks in advance
The second output,
<null>, comes from theNSNullsingleton. This is a class calledNSNullthat has a class method+nullthat returns the same singleton instance ofNSNullevery time. The primary purpose of this class it to be able to act as a stand-in fornilin places where you can’t putnil, such as in collections. For example, JSON libraries typically returnNSNullwhen the JSON includesnull.You can test for this simply by asking if it’s
==to[NSNull null](since it’s a singleton), or possibly if[obj isKindOfClass:[NSNull null]]. You could use[obj isEqual:[NSNull null]]if you like. You could even ask if it’s== kCFNullif you want, sinceCFNullandNSNullare toll-free bridged. Whatever style you want is up to you.