Saturday, May 18, 2013

NSString localizedStandardCompare example ios

[NSString localizedStandardCompare]

Compares strings as sorted by the Finder.
- (NSComparisonResult)localizedStandardCompare:(NSString *)string
The string to compare with the receiver.
Return Value
The result of the comparison.
Discussion of [NSString localizedStandardCompare]
This method should be used whenever file names or other strings are presented in lists and tables where Finder-like sorting is appropriate. The exact sorting behavior of this method is different under different locales and may be changed in future releases.
Example of [NSString localizedStandardCompare]
NSArray *sorted = [foo sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
    // Remove all spaces
    NSString *s1 = [str1 stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *s2 = [str2 stringByReplacingOccurrencesOfString:@" " withString:@""];

    return [s1 localizedStandardCompare:s2];
Example of [NSString localizedStandardCompare]
NSArray *sortedValues = [[yourDictionary allValues] sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
NSMutableDictionary *orderedDictionary=[[NSMutableDictionary alloc]init];
for(NSString *valor in sortedValues){
    for(NSString *clave in [yourDictionary allKeys]){
        if ([valor isEqualToString:[yourDictionary valueForKey:clave]]) {
            [orderedDictionary setValue:valor forKey:clave];
Example of [NSString localizedStandardCompare]
sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedStandardCompare:)];