I have a function that returns "id". Does this include a return of void? (as in nothing) Or does "id" require some kind of object/variable?
-
1Possible duplicate: http://stackoverflow.com/questions/7987060/objective-c-the-meaning-of-id – mk12 Feb 05 '12 at 04:13
-
@Mk12 Not really. I am not asking about what id is I am asking about a specific type of usage for it. – fdh Feb 05 '12 at 04:34
-
You are asking if `id` can also be considered as `void`, and by definition it can't. By the way you could have very easily tested this for yourself by reading the warnings that appear when you return nothing from a method with a return type of `id`. – mk12 Feb 05 '12 at 04:39
-
and from apple https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW2 – vikingosegundo Feb 05 '12 at 04:57
4 Answers
In Objective-C, id
is a keyword that represents an untyped object pointer. It's kinda like void*, the untyped pointer, but it adds the restriction that the pointer must point to some sort of Objective-C object.

- 124,013
- 19
- 183
- 272
id
is a general data type that can wrap most objects. If you can, you usually want to opt for coding specific data types, but if the situation (in a method for example) can use a wide range of data types, id
is used.
This Stackoverflow post should help to explain what it is and when to use it. A simple Google search will also turn up information.
In Objective C, id
means object of any type
, akin to void*
in C/C++. You can return nil
for from a function returning id
to indicate that you do not want to return anything in particular.

- 714,442
- 84
- 1,110
- 1,523
'id' is a pointer to an instance of an Objective-C class. So your method can return a pointer to an instance, or 'nil' (a zero pointer).

- 23,007
- 8
- 61
- 83