Need help to sort NSArray that contains åäö (Swedish chars) I am using for the moment
[keyArray addObjectsFromArray:[[names allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
But this is sort A Å Ä Ö
This question is similar to the one I answered here Sort NSArray of NSStrings like Addressbook on iphone sort . You need to do a diacritic insensitive search.
NSArray *array = [NSArray arrayWithObjects:@"aar", @"åäö", @"aao", nil];
NSArray *sorted = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [(NSString*)obj1 compare:obj2 options:NSDiacriticInsensitiveSearch|NSCaseInsensitiveSearch];
}];
Note: sortedArrayUsingComparator:
requires iOS 4.0 and above. For iOS < 4.0 use sortedArrayUsingSelector:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With