-1

Possible Duplicate:
How can I reverse a NSArray in Objective-C?

Is there a way to reverse the elements in a NSMutableArray?

Community
  • 1
  • 1
Saturn
  • 17,888
  • 49
  • 145
  • 271
  • 3
    Have you searched this site, or even taken a look at the suggestions made to you as you entered the title of your question? – BoltClock Feb 13 '11 at 20:58

2 Answers2

2

How can I reverse a NSArray in Objective-C?

Community
  • 1
  • 1
Rog
  • 18,602
  • 6
  • 76
  • 97
2

I don't think that there is an easy way to do it. Best way that I came up with is the exchangeObjectAtIndex:withObjectAtIndex: function.

pseudo code:

NSMutableArray* array = [NSMutableArray arrayWithObjects:@"1", @"2", @"3",nil];
for(i = 0, len = (int)[array count]/2; i < len; i++)
{
  [array exchangeObjectAtIndex:i withObjectAtIndex:([array count] - i - 1)];
}

Don't have the compiler open right at this moment but hopefully this does the trick.

mistagrooves
  • 2,337
  • 15
  • 16