-5

NSMutableArray looks like ("xxx_20", "xxx_18", "xxx_16", "xxx_19", "xxx_17")

I want to sort it into ("xxx_16", "xxx_17", "xxx_18", "xxx_19", "xxx_20")

I've tried to use selectors, but I can't even get proper syntax. Does anyone know how to do this properly?

methodmain
  • 230
  • 2
  • 11

1 Answers1

1

Try this,

 NSMutableArray *myarray = [ NSMutableArray arrayWithObjects:@"xxx_20", @"xxx_18", @"xxx_16", @"xxx_19", @"xxx_17", nil];
    NSArray *sortedArray = [myarray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
    NSLog(@"%@",sortedArray);

It worked fine at my end.

Ramu Pasupuleti
  • 888
  • 2
  • 15
  • 35
  • Thanks. That did work. The selector I tried with wasn't sorting it in the order I expected. So I was trying to create my own custom selector based on a slice of just the digits and casting to ints. This is much easier. – methodmain Apr 12 '13 at 09:45