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.