Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'Nil' represent in Obj-C?

Tags:

objective-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?

like image 849
Jaka Jančar Avatar asked Feb 28 '23 09:02

Jaka Jančar


1 Answers

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.

like image 115
Damien_The_Unbeliever Avatar answered Mar 12 '23 16:03

Damien_The_Unbeliever