2

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

I've NSMutableArray *mutArray = [[NSMutableArray alloc]initWithObjects:obj1,obj2,obj3,nil]; and each object have name, title, address but i want to show mutArray in another NSMutableArray which shows in reverse order it means obj3, obj2 & then obj1 , nil how i do it.

Community
  • 1
  • 1
iOS_User
  • 1,372
  • 5
  • 21
  • 35
  • Already answered here http://stackoverflow.com/questions/586370/how-can-i-reverse-a-nsarray-in-objective-c – Rog Nov 23 '10 at 09:14

2 Answers2

6

You can do this on this way:

NSMutableArray* reversedArray = [[NSMutableArray alloc] initWithArray:[[[[NSArray alloc] initWithArray: mutArray] reverseObjectEnumerator] allObjects]];
marko
  • 1,336
  • 2
  • 12
  • 25
0

I did the following and it worked for me:

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc]
                 initWithKey:@"key"  ascending:YES];

[mutableArray sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];

mutableArray = [mutableArray copy];

[descriptor release];

Hope it helps!