Know the index with fast enumeration?


When using fast enumeration is it possible to determine the index?


Good question. This looks like a good conversation on the topic: … numeration


Wow, blocks look cool but I’m going to wait until I get to that chapter.

In the meantime, I’m wondering if the efficiency of fast enumeration is lost if you manage an index (increment a counter) in the loop. In other words, if you’re not ready for blocks yet and you need the index, should you just use an ordinary for loop?


Apple suggests just using a counter: … ation.html

“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.” You still get the same benefits of fast enumeration and immutability of the array.