Fast enumeration of an NSArray with index

suggest change

This example traverses an NSArray and also reports each object’s index.

Suppose you have an array,

NSArray *weekDays = @[@"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday", @"Sunday"];

Now you can traverse through the array like below,

[weekDays enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

    //... Do your usual stuff here

    obj   // the current object
    idx   // the index of the current object
    *stop = YES; // set this to stop enumeration early

}];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents