Objective-C Language Fast Enumeration Fast enumeration of an NSArray

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

This example shows how to use fast enumeration in order to traverse through an NSArray.

When you have an array, such as

NSArray *collection = @[@"fast", @"enumeration", @"in objc"];

You can use the for ... in syntax to go through each item of the array, automatically starting with the first at index 0 and stopping with the last item:

for (NSString *item in collection) {
    NSLog(@"item: %@", item);
}

In this example, the output generated would look like

// item: fast
// item: enumeration
// item: in objc


Got any Objective-C Language Question?