fast-enumeration
Does fast enumeration in Objective-C guarantee the order of iteration?
From Apples’ Objective-C documentation on fast enumeration: For collections or enumerators that have a well-defined order—such as NSArray or NSEnumerator instance derived from an array—the enumeration proceeds in that order, so simply counting iterations will give you the proper index into the collection if you need it.
Fast enumeration over nil object
Fast enumeration is implemented through the method – countByEnumeratingWithState:objects:count:, which returns 0 to signal the end of the loop. Since nil returns 0 for any method, your loop should never execute. (So it’s safe.)
What is the BOOL *stop argument for enumerateObjectsUsingBlock: used for?
The stop argument to the Block allows you to stop the enumeration prematurely. It’s the equivalent of break from a normal for loop. You can ignore it if you want to go through every object in the array. for( id obj in arr ){ if( [obj isContagious] ){ break; // Stop enumerating } if( ![obj … Read more