In fact, I would like to study the difference between nil, nil, null and nsnull, but only nil on the job, the other almost rarely used, so has been dragged to today. Sometimes feel more and more impetuous, the knowledge of the subtle understanding is not deep enough, so here to remind yourself--in the future work should always maintain a spirit of study!
Let's go back to the four different types:
One, nil
When we assign a value to an object, we generally use object = nil, which means I want to release the object;
Or the object for some reason, after several releases, so the object reference counter is 0, the system will release this memory, this time this object is nil, I call it "empty object". (Note: I emphasize here is "empty object", below I will take it and "value is empty object" against!!! )
So for this empty object, all operations on retain will cause the program to crash, such as dictionary add key value or array to add new primitives, etc., refer to the following code:
Second, NSNull
The difference between nsnull and nil is that nil is an empty object that has completely disappeared from memory, and if we want to express the idea that we need to have such a container but nothing in this container, we use nsnull, which I call "the object with a value of NULL." If you look at the development documentation you will find NSNull this class is inherited nsobject, and there is only one "+ (NSNull *) null;" Class method. This means that the Nsnull object has a valid memory address, so any references to it in the program will not cause the program to crash. (This is not entirely true, such as data retrieved from the server, if there is a dictionary or an array of Nsnull objects, then there will be an error) the reference code is as follows:
Third, Nil
Nil and nil are not strictly limited in use, which means that nil can be used wherever nil is substituted, and vice versa. But from the programmer's Statute we have conventionally represented nil as an empty object, and nil represents an empty class. The reference code is as follows:
Four, NULL
We know that object-c originates from C, supports C, and of course differs from C. And Null is the typical C language syntax, which represents a null pointer, the reference code is as follows:
int *ponit = NULL;
Reproduced in
http://blog.sina.com.cn/s/blog_4930f8e60101h71b.html
The difference between nil, nil, nsull, and Null for iOS