Reputation: 7484
will a fast enumeration of an array always go in index order?
for (NSDictionary *zone in myArray)
{
//do code
}
will that always enumerate from index location 0, 1, 2, ..., n?
i prefer fast enumeration over a standard for loop since it makes the code easier to read.
Upvotes: 8
Views: 1779
Reputation: 4977
For fast enumeration of an array with indexes, use blocks:
[myArray enumerateObjectsUsingBlock:^(NSObject *object, NSUInteger idx, BOOL *stop) {
...
// idx is myArray's index
}];
Upvotes: 4
Reputation: 5820
Yes it will:
For collections or enumerators that have a well-defined order—such as an NSArray or an NSEnumerator instance derived from an array—the enumeration proceeds in that order, so simply counting iterations gives you the proper index into the collection if you need it.
Upvotes: 17