Created
January 12, 2013 15:39
-
-
Save h2rd/4518524 to your computer and use it in GitHub Desktop.
Sort array with blocks
This file contains hidden or 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
| NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { | |
| if ([obj1 integerValue] > [obj2 integerValue]) { | |
| return (NSComparisonResult)NSOrderedDescending; | |
| } | |
| if ([obj1 integerValue] < [obj2 integerValue]) { | |
| return (NSComparisonResult)NSOrderedAscending; | |
| } | |
| return (NSComparisonResult)NSOrderedSame; | |
| }]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment