Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NSArray for-loop enumeration order guaranteed?

Pretty straightforward question here: is the enumeration order in a for loop guaranteed to follow the order of an NSArray target (i.e. start at object index 0 and increment by 1 each time)?

Specifically, is the enumeration order in the following code snippet guaranteed to start at array index 0 and increment by 1 each loop? (codesArray is an NSArray)

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

Or if I want to guarantee enumeration order do I have to do a traditional for loop of the style:

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

Thanks!

like image 588
Murdock Avatar asked Nov 18 '11 01:11

Murdock


1 Answers

Yes, these will follow a guaranteed order as you would expect.

like image 188
Joshua Weinberg Avatar answered Nov 07 '22 19:11

Joshua Weinberg