8. Enumerators

Enumerators provide a mechanism for accessing all of the objects in a collection sequentially without exposing the collection’s underlying data structures. Enumerators are used to write flexible and efficient code for using collection classes without tying applications to specific implementations. Furthermore, enumerators provide a uniform interface to collection classes that can be extended to meet a wide range of needs including alternative traversal orders and algorithms.

Enumerators rely on the Anonymous Type pattern and make Heterogeneous Containers more powerful. Objective-C 2.0, available with Mac OS 10.5, Leopard, adds language features to further enhance Enumerators by reducing the amount of repetitive code needed to ...

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.