Fast Enumeration with Collections

Fast enumeration is an Objective-C’s feature that helps in enumerating through a collection.

Collections in Objective-C

Collections are fundamental constructs. It is used to hold and manage other objects. The whole purpose of a collection is that it provides a common way to store and retrieve objects efficiently.

There are several different types of collections. While they all fulfil the same purpose of being able to hold other objects, they differ mostly in the way objects are retrieved. The most common collections used in Objective-C are:

NSSet

NSArray

NSDictionary

NSMutableSet

NSMutableArray

NSMutableDictionary

Fast enumeration Syntax

for (classType variable in collectionObject )
{
statements
}

Here is an example for fast enumeration.

Leave a Reply