Question

Is there any differences in the sorting order when using this (for in-memory sorting)

[[UILocalizedIndexedCollation currentCollation] sortedArrayFromArray:namesArray collationStringSelector:@selector(sortName)]

and this (for CoreData sorting)

fetchRequest.sortDescriptors =
    [NSArray arrayWithObject:[NSSortDescriptor
                              sortDescriptorWithKey:@"name" ascending:YES
                              selector:@selector(localizedStandardCompare:)]];

I want to store a huge data set with CoreData, and then show it in a TableView. In this case, if any record changes, I'll need to resort the whole array using the first method, and this will take a while, so the second method is much more preferable.

I know that for the English language the sorting order should be the same, but I don't really know about languages which use letters with umlauts and which use non-latin letters.

Your help will be greatly appreciated.

Was it helpful?

Solution

One difference is that with UILocalizedIndexedCollation, non-latin characters seem to get sorted phonetically when your locale is en_US. For instance, on an English iPhone, ス (pronounced "su") would go under "S", together with other words that really do with "S". With localizedStandardCompare:, the same ス character would go in after Z.

Latin characters with diacritics seem to be treated the same way with both sorts (e.g. "Aaa" < "Åab" < "Aac" with both UILocalizedIndexedCollation and localizedStandardCompare:).

There are probably plenty more differences, especially when you start setting your device to other locales. I haven't figured out how to get CoreData to sort the same way as UILocalizedIndexedCollation unfortunately, so have resorted to either using in-memory arrays or avoiding UILocalizedIndexedCollation altogether depending on the requirements. If anybody knows a better way that'd be awesome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top