I want to sort an array I have so that the Umlauts are treated as normal versions of the characters (ä == a, etc.). I thought localizedCaseInsensitiveCompare: should do the trick. But it doesn’t. Anyone?
Best
–f
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
localizedCaseInsensitiveCompare:compares using the standard rules in the current language chosen by the user, ignoring the case. In your case you want to disregard the diacritics, not the case. This means you need to do something else.You need to use
compare:options:and passNSDiacriticInsensitiveSearchas an option. see here.To sort an array using it, you need to either use a block using
sortedArrayUsingComparator:, or implement a category method inNSStringand pass that selector tosortedArrayUsingSelector:. Don’t forget to prefix the name of the category method so that it doesn’t overlap with a private method in the framework. So, do something like