NSStringCompareOptions, Translation
TypedefNS_OPTIONS (NSUInteger, NSStringCompareOptions ){
NSCaseInsensitiveSearch = 1, // case-insensitive comparison
NSLiteralSearch = 2, // case-sensitive by byte
NSBackwardsSearch = 4, // search from the end of the string
NSAnchoredSearch = 8, // search for a restricted string
NSNumericSearch = 64, // calculate the order based on the numbers in the string. For example, Foo2.txt <Foo7.txt <Foo25.txt
NSDiacriticInsensitiveSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 128, // ignore the comparison of the "-" symbol
NSWidthInsensitiveSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 256, // ignore the length of the string and compare the result
NSForcedOrderingSearchNS_ENUM_AVAILABLE (10_5, 2_0) = 512, // ignore case-insensitive options, and forcibly return NSOrderedAscending or NSOrderedDescending
Round (10_7, 3_2) = 1024 // it can only be applied to rangeOfString:..., stringByReplacingOccurrencesOfString:... And replaceOccurrencesOfString:... method. If this option is set, NSCaseInsensitiveSearch and NSAnchoredSearch can be removed.
};
NSArray * stringsArray = [NSArrayarrayWithObjects:
@ "String 10 ",
@ "String 1 ",
@ & Quot; string 120 & quot ",
@ & Quot; String 1100 & quot ",
"String 02000", nil];
NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch;
NSLocale * currentLocale = [NSLocalecurrentLocale];
NSComparator finderSortBlock = ^ (id string1, id string2 ){
Nsange string1Range = NSMakeRange (0, [string1length]);
Return [string1compare: string2options: comparisonOptionsrange: string1Rangelocale: currentLocale];
};
NSArray * finderSortArray = [stringsArraysortedArrayUsingComparator: finderSortBlock];
NSLog (@ "finderSortArray: % @", finderSortArray );
FinderSortArray :(
"String 1 ",
"String 10 ",
& Quot; string 120 & quot ",
& Quot; String 1100 & quot ",
& Quot; String 02000 & quot"
)