Skip to content

Instantly share code, notes, and snippets.

@jrodriguez-ifuelinteractive
Last active February 23, 2017 20:01
Show Gist options
  • Save jrodriguez-ifuelinteractive/baf4fcd033d1adcdc856 to your computer and use it in GitHub Desktop.
Save jrodriguez-ifuelinteractive/baf4fcd033d1adcdc856 to your computer and use it in GitHub Desktop.
Sort Objective-C Array
// 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