1.nil
>defines the ID of a null instance.
Defines an instance that is empty, pointing to an empty pointer to an object in OC.
> Sample code:
NSString *somestring = nil;
Nsurl *someurl = nil;
ID someobject = nil;
if (Anotherobject = = nil)//do something
> When you release an object, it is best to assign them to nil, which ensures security, which can cause a crash if you do not assign a value of nil.
Nsarray * array = [Nsarray arraywithobjects:@ "test", @ "Test1", nil];
[Array release];
if (array)
{
Only the array release, not assigned to nil, somewhere in the program if you continue to operate the array, the program directly crashes
NSString * string = [array objectatindex:0];
NSLog (@ "%@", string);
}
2.NULL
>these macros define null values for classes and instances.
Null can be used on various pointers in the C language,
#define __DARWIN_NULL #define__DARWIN_NULLConstants
> Sample code:
int *pointertoint = NULL;
char *pointertochar = NULL;
struct TreeNode *rootnode = NULL;
> in objective-c, nil objects are designed to be associated with NULL null pointers. The difference is that nil is an object, and null is just a value. And we call the method on the nil without generating crash or throwing an exception.
3.Nil
>defines the ID of a null class.
To define an empty class
Available in Mac OS X v10.0 through Mac OS X v10.4.
Declared in NSObjCRuntime.h.
Declared Inobjc.h
> Sample code:
Class SomeClass = Nil;
Class Anotherclass = [NSString class];
4.NSNull
>the Nsnull class defines a singleton object used to represent null values in collection objects (which don ' t allow Nil Values).
The Nsnull class defines a single instance object to represent the null value of a collection object
> Collection objects cannot contain nil as their specific values, such as Nsarray, Nsset, and Nsdictionary. Accordingly, the nil value is represented by a specific object nsnull. Nsnull provides a single instance to represent the nil value in an object property. The default implementation method, Dictionarywithvaluesforkeys: And setvaluesforkeyswithdictionary: automatically converts nsnull and nil to each other, so your object does not need to perform nsnull test operations.