16

Possible Duplicate:
What is the meaning of id?

Per my question I'm obviously a noob at iOS development and Objective-C. I was following a tutorial and I have this line declared in my interface (.h) implementation:

@property (strong, nonatomic) id dataObject1;

What does the "id" mean?

Community
  • 1
  • 1
ScoobaSteve
  • 543
  • 1
  • 5
  • 19
  • @H2CO3 I did a fair amount of googling and didn't find the answer. I apologize for the question. – ScoobaSteve Jan 10 '13 at 23:01
  • @ScoobaSteve Okay, no hard feelings, I was just surprised... If you need good Objective-C resources, [this may be helpful](http://gnustep.made-it.com/BG-objc/). –  Jan 10 '13 at 23:06
  • 2
    @HermannKlecker Are you serious... Was it really so important to post to LMGTFY that you needed to circumvent the ban and the friendly orange box that told you that the content you were posting wasn't allowed? – Mick MacCallum Jan 11 '13 at 00:18

1 Answers1

12

id is the type of the object; the type could have been NSArray * or int instead, for example.

The id type specifies a reference to any Objective-C object (no matter its class).

Metabble
  • 11,773
  • 1
  • 16
  • 29
praseodym
  • 2,134
  • 15
  • 29
  • 19
    No, id cannot be int. It is an alias of NSObject*. So it could be NSArrary* but not int. int is no object at all. It's a scalar. – Hermann Klecker Jan 10 '13 at 23:28
  • 1
    You're right, but I meant to explain the `@property` type declaration in general -- it is perfectly fine to declare a property with type `int`. – praseodym Jan 10 '13 at 23:36
  • 8
    @HermannKlecker That's incorrect. The `id` data type is *not* an alias of `NSObject *`; it's a `typedef` declared in **objc.h** as follows: `typedef struct objc_object { Class isa; } *id; ` – jlehr Jan 11 '13 at 01:23
  • @jlehr, still, as int is no class, it cannot represent int. And every NSObject* does comply with struct objc_object { Class isa; } * and a bit more. – Hermann Klecker Jan 11 '13 at 10:33
  • 2
    @HermannKlecker My point had nothing to do with the `int` data type. I was simply pointing out that `id` doesn't imply `NSObject`. For example, class structures and instances of `NSProxy` aren't subclasses of `NSObject`, but they match the `id` data type. – jlehr Jan 12 '13 at 20:20
  • Yes. And you are right. I made the point about the int and id incompatibility and did not intend to lecture on the exact definition. I was just focussing about some aspect of the answer that did not appear to be helpful. – Hermann Klecker Jan 12 '13 at 20:23
  • 2
    So is anyone going to actually correct the answer? – Daniel Viglione Mar 23 '16 at 18:54