Last active
February 23, 2017 20:01
-
-
Save jrodriguez-ifuelinteractive/baf4fcd033d1adcdc856 to your computer and use it in GitHub Desktop.
Sort Objective-C Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSMutableArray Example | |
// Using this method will sort your current array | |
NSMutableArray *unsortedArray = [[NSMutableArray alloc] initWithObjects:@"Albert", @"Eric", @"Betty", nil]; | |
[unsortedArray addObject:@"Carl"]; | |
[unsortedArray addObject:@"David"]; | |
[unsortedArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; | |
NSLog(@"sorted array: %@", unsortedArray); | |
// NSArray Example | |
// Using this method will create a new array | |
NSArray *unsortedArray = [[NSArray alloc] initWithObjects:@"Carl", @"David", @"Albert", @"Eric", @"Betty", nil]; | |
NSArray *sortedArray = [unsortedArray sortedArrayUsingSelector: @selector(localizedCaseInsensitiveCompare:)]; | |
NSLog(@"sorted array: %@", sortedArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment