I need to reverse my NSArray
.
As an example:
[1,2,3,4,5]
must become: [5,4,3,2,1]
What is the best way to achieve this?
nsarrayobjective c
I need to reverse my NSArray
.
As an example:
[1,2,3,4,5]
must become: [5,4,3,2,1]
What is the best way to achieve this?
Best Answer
There is a much easier solution, if you take advantage of the built-in
reverseObjectEnumerator
method onNSArray
, and theallObjects
method ofNSEnumerator
:allObjects
is documented as returning an array with the objects that have not yet been traversed withnextObject
, in order: