In Cocoa, NULL is not really used, but usually reserved for those cases where standard C pointers are employed.
Since Objective-C is also C, this is of course just a convention, but a useful one - it allows you to set an NSString* pointer to nil, and a char* or void* pointer to NULL, and notice the difference at a glance.
Further, in Cocoa, collections (arrays, dictionaries, sets) can't hold nil values, so as other posters have noted, you have to use a placeholder, namely [NSNull null].
But notice that [NSNull null] is just that, a placeholder, and since collections can only hold objects, this placeholder is also a standard Objective-C object.
Hence, you need to test properly for it if you use it in conditional statements, for instance:
id myVar = [NSNull null];
// Stuff...
if ( myVar == [NSNull null] ) {
// myVar has not been changed, do something
}
This is different from the standard C idiom, where you can test a NULL value directly in the conditional statement:
void *myPointer = NULL;
// Stuff...
if ( myPointer ) {
// More stuff if pointer uninitialized
}
You might also wonder why it is suddenly all right to test a variable for equality with [NSNull null] using the == operator? That is because [NSNull null] is a singleton, guaranteed to have always the same position in memory (which is what == tests in this case). Don't do this with normal objects.
More about it in the docs.
NULLis the same asniland has the memory address0x0000000.[NSNull null]is an object that is notnil, but representsnilandNULL. It is what you should use here.