-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?

0

1 Answer 1

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.

1
  • 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, 2013 at 9:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.