Reputation: 11
I'm curious why a variable overtly assigned to nil, prints as (null) with NSLog:
NSString *myVar = nil;
NSLog(@"%@", myVar);
# RESULT: ' (null) '
This is of course quite confusing given all the different kinds of "nothingness" to figure out in Objective-C, and had me trying to test various IF NULL syntaxes.
Upvotes: 1
Views: 3462
Reputation: 7966
It's just the implementation of the method NSLog IMHO
.
Upvotes: 2
Reputation: 1008
This is what %@
format does, it casts nil
to NSNull
. myVar
itself is still nil
. You can still use if (myVar)
for testing.
Upvotes: 2
Reputation: 34253
The different kinds of "nothingness" summed up:
nil //Null pointer to an Objective-C object
Nil //Null pointer to an Objective-C class
NULL //Null pointer
All of the above are defined as ((void *)0)
.
Upvotes: 9
Reputation: 39019
(null) is the string representation of 'nil' for printing purposes... nothing related to IF NULL
checks. myVar is still nil
Upvotes: 4