1.nil
>defines the ID of a null instance.
Defines a null pointer to an object in OC that has an empty instance.
> Sample code:
NSString *somestring = nil;
Nsurl *someurl = nil;
ID someobject = nil;
if (Anotherobject = = nil)//do something
> When it's time to release an object, it's best to assign them to nil, which ensures security, and if you don't assign nil, it can cause the program to crash.
Nsarray * array = [Nsarray arraywithobjects:@ "test", @ "Test1", nil];
[Array release];
if (array)
{
Only an array of release, and no assignment to nil, somewhere in the program if you continue the array operation, 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, the nil object is designed to be associated with a NULL null pointer. The difference is that nil is an object, and null is just a value. And we're not going to generate crash or throw exceptions for the nil call method.
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 singleton object used to represent the null value of a collection object
> Collection objects cannot contain nil as their specific value, such as Nsarray, Nsset, and Nsdictionary. Accordingly, the nil value is represented by a specific object nsnull. Nsnull provides a single instance for representing the nil value in the object's properties. 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.
An explanation of nil, NULL, nil, nsnull in iOS (i)