Jaka Jančar
Jaka Jančar

Reputation: 11606

What does 'Nil' represent in Obj-C?

So there 's NULL, which is used for pointers in general, and nil, which is used for object pointers.

Now I see there's also Nil, which is used by lower-level Obj-C runtime functions like class_getProperty.

Is this somehow different from nil philosophically? (yes, I know they're all actually 0)

Why was it even introduced? Or, if Nil was first (which is likely), why was nil introduced?

Upvotes: 4

Views: 1720

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239824

Googling "Nil vs nil" found this post http://numbergrinder.com/node/49, which states:

All three of these values represent null, or zero pointer, values. The difference is that while NULL represents zero for any pointer, nil is specific to objects (e.g., id) and Nil is specific to class pointers. It should be considered a best practice of sorts to use the right null object in the right circumstance for documentation purposes, even though there is nothing stopping someone from mixing and matching as they go along.

Upvotes: 8

Related Questions