What is the difference among nil, NULL, Nil in Objective-C?



They are all zeros, the difference lies in their types
-> The NSNull class defines a singleton object used to represent null values in collection objects (which don’t allow nil values). {NSNull is a class for objects that represent null.}
(https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNull_Class/Reference/Reference.html#//apple_ref/occ/cl/NSNull)
-> nil is an id. So its points to a non-existent objective-c object
-> Nil is a non-existent objective-c class
-> [NSNull null] is an object that’s meant to stand in for nil in situations where nil isn’t allowed. For example, you can’t have a nil value in an NSArray. So if you need to represent a “nil”, you can use [NSNull null]
Also there is no ‘null’ in the objective c its ‘NULL’ not ‘null’. ‘null’ exist in Java or in C# not in Objective-C

nil -> Null-pointer to objective- c object
NIL -> Null-pointer to objective- c class

null-> null value for C pointer.

NSNUll -> Singleton object used to represent null.



NSNull     [NSNull null]     singleton object used to represent null
nil is the literal null value for Objective-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 Objective-C classes, corresponding to the type Class. Since most code doesn’t need variables to reference classes, its use is not common. One example is:
 Class someClass = Nil;
 Class anotherClass = [NSString class];
Link (http://stackoverflow.com/questions/9578748/iphone-difference-between-nil-vs-nil-and-true-vs-true)

Comments

Popular posts from this blog

Hacker Rank problem solution

How to Make REST api call in Objective-C.

Building and Running Python Scripts with Xcode