Type id

The id data type is used to store an object of any type. In a sense, it is a generic object type. For example, this line declares graphicObject to be a variable of type id:

id   graphicObject;

Methods can be declared to return values of type id, like so:

-(id) newObject: (int) type;

This declares an instance method called newObject that takes a single integer argument called type and returns a value of type id.

The id data type is an important data type used often in this book. We mention it in passing here for the sake of completeness. The id type is the basis for very important features in Objective-C known as polymorphism and dynamic binding, which Chapter 9, “Polymorphism, Dynamic Typing, and Dynamic Binding,” discusses extensively. ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.