Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: block enumeration for array in REVERSE order? [duplicate]

There is the enumerateWithBlock method of NSArray, but I need to enumerate in a reverse order, is there a block for doing that, or do I have to use for loop instead, not even the fast loop, but the traditional for (int i = array.count - 1 ; i >= 0 ; i--) one?

Thanks!

like image 271
hzxu Avatar asked Nov 28 '22 02:11

hzxu


2 Answers

You can use enumerateObjectsWithOptions:usingBlock: passing NSEnumerationReverse as the options parameter.

like image 166
rdelmar Avatar answered Dec 05 '22 10:12

rdelmar


You can use reverseObjectEnumerator

for (id someObject in [myArray reverseObjectEnumerator])
{
    // print some info
    NSLog([someObject description]);
}

Hope this helps!

like image 32
Eric Avatar answered Dec 05 '22 08:12

Eric