3

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.

dmirkitanov
  • 1,396
  • 1
  • 12
  • 29

1 Answers1

2

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.

nioq
  • 3,215
  • 1
  • 23
  • 18
  • I've ended up calculating intermediate "sort value", and storing it to CoreData. UILocalizedIndexedCollation uses it's own mapping tables for indexes and letters (which are really buggy for some languages), and it is not possible to sort with CoreData using this "indexed collation", simply because CoreData(SQLite really) doesn't have these mappings. – dmirkitanov Apr 26 '13 at 13:22