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...
nil is an Object, NULL is a memory pointer Sadly, when this happens, Ruby developers are confusing a simple little Ruby object for something that's usually radically different in “blub” language. Often, this other thing is a memory pointer, sometimes called NULL, which traditionally has the value 0.
Objective-C builds on C's representation of nothing by adding nil . nil is an object pointer to nothing. Although semantically distinct from NULL , they are technically equivalent.
Well, "nil" is the traditional name for the reified concept of "nothing" in Lisp and Smalltalk†. The word "null" is used as an adjective meaning "empty", as in "the null list," which is nil. Meanwhile, "null" is traditionally a pointer value in C that signifies the pointer doesn't point to anything valid.
There is no difference, as . none (basically it's Optional. none ) and nil are equivalent to each other. The use of nil is more common and is the recommended convention.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With