Created
October 11, 2012 14:22
-
-
Save boboboa32/3872686 to your computer and use it in GitHub Desktop.
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
NSArray *stringsArray = @[ @"string 1", | |
@"String 21", | |
@"string 12", | |
@"String 11", | |
@"String 02" ]; | |
static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | | |
NSWidthInsensitiveSearch | NSForcedOrderingSearch; | |
NSLocale *currentLocale = [NSLocale currentLocale]; | |
NSComparator finderSortBlock = ^(id string1, id string2) { | |
NSRange string1Range = NSMakeRange(0, [string1 length]); | |
return [string1 compare:string2 options:comparisonOptions range:string1Range locale:currentLocale]; | |
}; | |
NSArray *finderSortArray = [stringsArray sortedArrayUsingComparator:finderSortBlock]; | |
NSLog(@"finderSortArray: %@", finderSortArray); | |
/* | |
Output: | |
finderSortArray: ( | |
"string 1", | |
"String 02", | |
"String 11", | |
"string 12", | |
"String 21" | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment