Changes

Jump to: navigation, search

Working with Objective-C Array Objects

597 bytes added, 17:11, 9 November 2009
Sorting Array Objects
<pre>
NSMutableArray *myColors = [NSMutableArray arrayWithObjects: @"red", @"green", @"blue", @"yellow", nil];
 
NSArray *sortedArray;
 
sortedArray = [myColors sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
</pre>
 
As we can see from the above example, the method returns a new array containing the elements of the original array sorted using the ''localizedCaseInsensitiveCompare'' method. In practice any method can be used in this context as long as that method is able to compare two objects and return an ''NSOrderedAscending'', ''NSOrderedSame'' or ''NSOrderedDescending'' result.

Navigation menu