Chapter 7: Anonymous Type and Heterogeneous Containers

The anonymous type is our old standby, the id. The Cocoa type id indicates a generic pointer, which can point to any kind of object. In C++, every pointer to an object must have a defined type, and assigning a different type object to the pointer gives a compilation error unless the pointer is cast to the object’s type.

Most Cocoa container classes hold objects of type id, so they can work with user-defined objects without subclassing. Furthermore, the objects in the container don’t have to have the same type, either. Since almost every practical program uses classes like NSArray, NSMutableArray, NSSet and NSMutableSet, I don’t think I need to write any example code: I’ve used them frequently myself, and I’m sure you have, too. At least one of these will see use in almost every program you’ll see in this blog, so I’ll pass on writing any special programs for this chapter.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s