Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aztec31

macrumors newbie
Original poster
Sep 15, 2008
9
0
How would I sort a small NSMutableArray that has NSNumber objects. I want to arrange the array in ascending order so the smaller numbers are at the beginning of the array. I looked at the docs but there isn't much examples that are clear. Can someone provide an example?
 

aztec31

macrumors newbie
Original poster
Sep 15, 2008
9
0
I kind of figured it out. I used
[myArray sortUsingSelector: @selector(compare:)];

but could someone explains what @selector means or does?

By the way this is not for a homework assignment.
 

Fontano

macrumors member
Jun 27, 2008
72
0
Assuming myArray is of type NSMutableArray

Code:
NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey:@"property_or_method_of_objects" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:mySorter];

So take a look at the API documents for NSSortDescriptor for adjustments you may need for your specific case.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.