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 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.