What is difference between nil
and Nil
? nil
is an uninitialised object, what is about Nil
? Thanks!

- 18,550
- 13
- 57
- 90
-
1it should help you : http://stackoverflow.com/questions/9578748/iphone-difference-between-nil-vs-nil-and-true-vs-true – Franck Nov 29 '13 at 15:07
3 Answers
It's the zero value for the Class
type.
All of NULL
, nil
, Nil
, NUL
, '\0'
, 0
, 0L
, 0U
, 0.0
, 0.0f
, ... have the same value (at least on sane systems). They just correspond to different types.
And to make this clear: nil
is not an "uninitialized object" but the value of an (initialized) variable of object pointer type.

- 81,520
- 17
- 180
- 200
-
Thanks! "You can accept an answer in 9 minutes". I will accept your answer soon! – nicael Nov 29 '13 at 15:13
-
3`Nil` is from `NeXTSTEP`, not from Russia. Both have seen better times. – Nikolai Ruhe Nov 29 '13 at 16:29
-
nil
is an uninitialised object
No, it isn't. It's a pointer-to-object that points nowhere. Uninitialized objects need not be nil
.
what is about
Nil
It's similar, but instead of objects, it is for classes only. (Since classes are objects in Objective-C, you could use nil
for a pointer of type Class
as well, but that is discouraged for code readability reasons.)
Adding a bit of pedantry....
nil
is a value that represents a pointer to a valid non-object. From a C perspective, it is a pointer to nowhere. However, it has special meanings in the context of Objective-C. Because Objective-C is a nil eats messages language, assigning nil
to an object pointer will make that object pointer effectively a no-op in all subsequent messaging operations.
nil
's value is defined as 0, but -- technically -- it doesn't have to be represented by zero bits (though it actually has to compare as equal to zero). Because standards.
In practice, nil
will be 0 exactly as Nikolai indicates.
Nil
is the same as nil
, but for Class object references as H2C03 mentions.