Friday, May 6, 2011

NSMutableArray sorting example - sortUsingSelector

A NSMutableArray sorting example using NSMutableArray:sortUsingSelector: method.
NSMutableArray:sortUsingSelector: method takes selector for a compare function as its argment. See following code.


NSMutableArray *a = [NSMutableArray arrayWithObjects:@"Cat", @"Dog", @"Fish", @"Squirrel", @"Bear", @"Turtle", nil];
[a sortUsingSelector:@selector(compare:)];