5

I am a relatively experienced iOS developer, however one thing has always bothered me, what is the difference between Nil(Capital) and nil(lowercase) and NULL (if any) in terms of performance and usage? I am absolutely sure that there is a difference between them otherwise why would they be defined as separately in the first place...

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
virindh
  • 3,775
  • 3
  • 24
  • 49

1 Answers1

15

The basic idea is that you use NULL for C pointers (0 for C primitives), nil for Objective C instances, Nil for Objective C classes, and NSNull as a way of pretending that nothing is something so that you can store an instance of nothing in an array or dictionary.

A great description of this and the source of the values listed below can be found at: http://nshipster.com/nil/

NULL (void *)0 literal null value for C pointers

nil (id)0 literal null value for Objective-C objects

Nil (Class)0 literal null value for Objective-C classes

NSNull [NSNull null] singleton object used to represent null

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281