Friday, May 6, 2011

NSArray sortedArrayUsingSelector example objc

Following code is an example of NSArray:sortedArrayUsingSelector method.
The comparator is given as a selector argument. Here we used default case-insensitive compare function. NSArray:sortedArrayUsingSelector is frequently used in list arrangement and so on, so it's worth to remember this example.

NSArray *sortedArray =
    [myArray2 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
    // This will return a sorted array that looks like [@"bar",@"baz",@"foo"]