8.9.3. Fast Enumeration Details
8.9.3 Fast Enumeration Details
Here is a more technical description with the gory details. Consider the code
for (object expression in collection expression) { statements }
here is what happens when you run it:
-
collection expression is evaluated exactly once and the result is used as the collection object to iterate over. This means it is safe to write code such as
for (object in [NSDictionary keyEnumerator]) ...
. - the iteration is implemented by the compiler by repeatedly getting batches of objects from the collection object using the fast enumeration protocol (see below), then iterating over all objects in the batch. This is faster than a normal enumeration where objects are retrieved one by one (hence the name “fast enumeration”).
- if there are no objects in the collection, then object ex