Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEric M
2,242 PointsIn Objective-C, is the generic `id` type only a generic for Objective-C objects, or any type of object?
In the video, it's emphasized that the generic type id
can "point to any class".
However (and this may be an unimportant distinction), it seems more likely to me that it may only point to instances of classes which extend NSObject
.
`id` [contains the set of]: NSArray, NSString, NSDictionary
`id` [does not contain]: Native C Array, Native C Object
What do you guys think, is this true?
1 Answer
Andrei Fecioru
15,059 PointsYes, you have a good intuition about this. In Objective C the id
type defines a pointer to any type, but is unlike void *
in vanilla C/C++ in that it always points to an Objective-C object. More specifically, it must point to a an object which inherits the NSObject
interface (the object must respond to the retain
and release
selectors).