My understanding is that nil
's behavior is part of the Objective C language, not of any particular library. NSNull
, on the other hand, is part of a library, with a single very specific purpose:
The
NSNull
class defines a singleton object used to represent null values in collection objects (which don’t allownil
values).
It is not intended for use as a "sentinel" object: if you wish to construct such an object, you can always do so, because collections themselves do not assign NSNull
any particular significance. It is provided for programmers' convenience in situations when they wish to store nil
s, so that programmers could avoid reinventing their own null object every time they need it.
Also note that [NSNull null]
is a singleton, so you can compare it with ==
/ !=
operators instead of calling isEqual:
if (name != [NSNull null] && [name isEqualToString:@"Gabriele"])