I’m building an app in xcode4.3/Objective-C and have come across a problem when trying to sort an NSMutableArray. I’ll populate it with strings from a sqlite database. The problem occurs with the swedish characters å, ä and ö.
The orded array should look something like this: as, br, ol, st, år, ög, ös.
But when I use the selector compare the order is this: as, år, br, ol, ög, ös, st.
And when I use localizedCompare the order change to: as, år, br, ög, ol, ös, st.
According to older threads the localizedCompare should be the solution, but I can’t make it work correctly. If I use the terminal to access the sqlite database and type ORDER I’ll get the correct result. Could my problem be related to some settings in xcode or the iphone simulator, since neither display the correct order? Or is localizedCompare the wrong way to go? I’ll happily accept any workarounds as long as it gets the job done. Thanks.
You can make it work by using
compare:options:range:locale:and specifying Swedish locale explicitly, like this:The output is: