Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:02
Show Gist options
  • Save alco/b1e8785dcac7b16d041e to your computer and use it in GitHub Desktop.
Save alco/b1e8785dcac7b16d041e to your computer and use it in GitHub Desktop.
// iPhone OS programming circa 2008
// ================================
NSInteger fruitSorter(NSString *a, NSString *b, void *context) {
return [a compare:b];
}
// ...
NSMutableArray *fruits = [[NSMutableArray alloc] initWithObjects:@"apple", @"pear", @"banana", nil];
[fruits sortUsingFunction:fruitSorter context:NULL];
// iOS programming circa 2013
// ==========================
NSMutableArray *fruits = @[@"apple", @"pear", @"banana"];
[fruits sortUsingComparator:^(NSString *a, NSString *b) { return [a compare:b]; }];
// iOS programming circa 2014
// ==========================
var fruits = ["apple", "pear", "banana"]
fruits.sort{ $0 < $1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment