1.nil pointer to an object is empty the definition in objc.h is as follows:
#ifndef nil# if __has_feature (cxx_nullptr) # define nil nullptr# else# define nil __darwin_null# endif#endif
Object in objective-c for ID type
NSString *name = nil; Nsurl *url = nil;id object = nil;
2.Nil pointers to a class are null defined as follows:
#ifndef nil# if __has_feature (cxx_nullptr) # define nil nullptr# else# define Nil __darwin_null# endif#endif
Objects for class type in Objective-c
Class aclass = Nil; Clsss Bclass = [Nsurl class];
3.NULL pointer to type C is empty as defined in Stddef.h:
#if defined (__need_null) #undef null#ifdef __cplusplus# if!defined (__mingw32__) &&!defined (_msc_ver) # define NULL __null# else# define NULL 0# endif#else# define NULL ((void*) 0) #endif
This is used for the following examples:
int *pint
4.NSNull is a class in objective-c, but there is a null,nsnull in the name+ (NSNull*) null; A singleton method that is used for objects with null values in the collection (nsarray,nsdictionary)
Nsarray *array = [Nsarray arraywithobjects: [[NSObject alloc] init], [NSNull null], @ "AAA", Nil, [[NSObject alloc] init], [[NSObject alloc] init], nil]; NSLog (@ "%ld", Array.count); Output 3,nsarray ends with nil
Nsdictionary *dictionary = [[Nsdictionary alloc] Initwithobjectsandkeys: @ "Object0", @ "Key0", @ "Object1", @ " Key1 ", Nil, @" Key-nil " @" Object2 ", @" Key2 ", Nil]; NSLog (@ "%@", dictionary); Output of 2 Key-value,nsdictionary is also terminated with nil
Nsmutabledictionary *mutabledictionary = [[Nsmutabledictionary alloc] init]; [Mutabledictionary setobject:nil forkey:@ "Key-nil"]; will cause crash[mutabledictionary setobject:[nsnull null] forkey:@ "Key-nil"]; does not cause crash
So in use, the following methods are relatively safe
[Mutabledictionary setobject: (nil = = value?) [NSNull NULL]: value) forkey:@ "Key"];
The difference between nil, nil, null and Nsnull