Is NSArray for-loop enumeration order guaranteed?

A rather simple question: is the enumeration order in the for loop guaranteed to correspond to the order of the NSArray target (i.e., start at object index 0 and increment by one each time)?

In particular, is the listing order in the next code fragment guaranteed to start at array index 0 and increment by 1 every cycle? ( codesArray is an NSArray)

 for (NSNumber *num in codesArray) { // do stuff // } 

Or, if I want to guarantee the order of enumeration, I need to make a traditional style for loop:

 for (int i=0; i<[codesArray count]; i++) { // do stuff // } 

Thanks!

+6
source share
1 answer

Yes, they will follow the guaranteed order, as you would expect.

+6
source

Source: https://habr.com/ru/post/901770/


All Articles