7. Anonymous Type and Heterogeneous Containers

Objective-C defines the type id, which is known as the Anonymous Type. The id type tells the compiler that a variable points to an object but doesn’t give the compiler any more specific information about the kind of object, hence the object is anonymous. Objective-C programmers quickly become familiar with the pervasive use of the Anonymous Type and forget that this feature is seldom encountered in other languages. Objective-C’s Anonymous Type and Cocoa’s Heterogeneous Containers deserve special recognition as patterns in their own right and facilitators for other patterns.

Motivation

Use the Anonymous Type pattern to send messages to anonymous objects, including objects that are not available ...

Get Cocoa Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.