ios nil Nil Null

i am newbie to iphone,here the difference between nil, Nil, Null;

nil -> Null-pointer to objective-c object

Nil -> Null-pointer to objective-c class

Null - > null pointer to primitive type or absence of data;(null 指针 ->一个原始的类型或缺失的对象)

here is details;

Follow me:

                  nil is the literal(字面) null value for Object-c objects,corresponding(匹配) to the abstract type id

or any Objective-C type declared via(声明) @interface,For instance:

              NSString *someString = nil;

              NSURL *someURL = nil;

              id  someObject = nil;

              if (anotherObject == nil) // do something

 

                  Nil is the Literal null value for Object-C class, corresponding to the type Class, Since most

code doesn't need variables to reference classes,its use is not common.One exampe is:

            Class someClass = Nil;

            Class anotherClass = [NSString class];

 

               NUll is the literal null value arbitracy C pointer , For instance:

             int *pointerToInt = NULL;

             char *pointerToChar = NULL;

             struct TreeNode *rootNode = NULL;

           NSNULL is a class for objects that represent null, in fact, there's only one object,namely the one returned by  +[NSNULL null](the same in java); It is different from nil,because nil is a literal null value,it isn;t an object,The single instance of NSNull ,on the other hand, is a proper object;

           the methods of too frequently

           NSMutableDictionary *dict = [NSMutableDictionary dictionary];

           [dict setObject:ni forKey:@"someKey"];   Error!!!!!!!!!!!!!!!!!!!!!!!!!

          [dict setObject:[NSNull null] forKey:@"someKey"];  

 

你可能感兴趣的:(null)