I. Nil
When assigning values to an object, we usually use object = nil, indicating that I want to release this object;
Or for some reason, after multiple release operations, the Reference Counter of the object is 0, and the system releases the memory. At this time, the object is nil, I call it an "Empty object ". (Note: Here I emphasize "Empty object". Next I will compare it with "an object with null value !!!)
Therefore, all retain operations on such empty objects will cause program crashes, such as Dictionary addition of key values or array addition of new elements.
Ii. nsnull
The difference between nsnull and nil is that nil is an empty object and has completely disappeared from the memory. If we want to express "we need to have such a container, but there is nothing in this container. We use nsnull, which is called an "Empty object ". If you read the development documentation, you will find that the nsnull class inherits nsobject and only has one "+ (nsnull *) NULL;" class method. This indicates that the nsnull object has a valid memory address, so any reference to it in the program will not cause the program to crash.
Iii. Nil
Nil and nil are not strictly limited in terms of use. That is to say, nil can be used in all places where NIL is used, and vice versa. In the programmer's conventions, we define nil as an empty object, and nil as an empty class. The reference code is as follows:
Nil, nil, null, and nsnull
Iv. null
We know that object-C comes from C and supports C, which is also different from C. Null is a typical C language syntax. It represents a null pointer. The reference code is as follows:
Int * ponit = NULL;
Differences between nil, nil, nsnull, and null