Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArray and fast enumeration, always go in index order?

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.

like image 882
Padin215 Avatar asked May 21 '12 16:05

Padin215


1 Answers

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.

docs here

like image 118
Sean Avatar answered Sep 19 '22 04:09

Sean