Nearly all object-oriented languages have the idea of nil, the pointer to no object. In Objective-C, nil is the zero pointer (same as NULL, which was discussed in Chapter 8).
In most object-oriented languages, sending a message to nil is not allowed. As a result, you have to check for non-nil-ness before accessing an object. So you see this sort of thing a lot:
if (fido != nil) { [fido goGetTheNewspaper]; }
When Objective-C was designed, it was decided that sending a message to nil would be OK; it just wouldn’t do anything at all. Thus, this code is completely legal:
Dog *fido = nil; [fido goGetTheNewspaper];
Important thing #1: If you are sending messages and nothing is happening, make sure you aren’t sending messages to a pointer that has been set to nil.
Important thing #2: If you send a message to nil, the return value doesn’t mean anything.
Dog *fido = nil; Newspaper *daily = [fido goGetTheNewspaper];
In this case, daily will be zero. (In general, if you expect a number or a pointer as a result, sending a message to nil will return zero. However, for other types like structs, you will get strange and unexpected return values.)