null vs nil vs [NSNULL null]
NSMutableArray *controllers = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < kNumberOfPages; i++) { [controllers addObject:[NSNull null]]; }
Directly from Apple: "The NSNull class defines a singleton object you use to represent null values in situations where nil is prohibited as a value (typically in a collection object such as an array or a dictionary)."
NSNull defines a singleton object, which means that there's only ever a single instance of NSNull (which you create using [NSNull null]), but it can be used in as many places as you wish.
Technically null and nil are same thing but differ only in style:
Objective-C style says nil is what to use for the id type (and pointers to objects).
C style says that NULL is what you use for void *.
C++ style typically says that you should just use 0.
nil should only be used in place of an id, what we Java and C++ programmers would think of as a pointer to an object. Use NULL for non-object pointers.
Look at the declaration of this method:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
Context is a void * (ie a C-style pointer), so you'd definitely use NULL (which is sometimes declared as (void *)0) rather than nil (which is of type id).
http://stackoverflow.com/questions/557582/null-vs-nil-in-objective-c
http://stackoverflow.com/questions/836601/whats-the-difference-between-nsnull-null-and-nil