I set my NSFetchRequests's
sortDescriptor
to an array that contains only one NSSortDescriptor
:
[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]
Then, I create a NSFetchResultsController
that also has @"name"
as its sectionKeyNamePath
.
When the locale is English, then letters with diacritical marks are sorted together with their plain letters. For instance, “Å” is treated as “A” for the purpose of sorting. The problem is that this is not taken into account when the fetch results are broken up into sections, so every time the sequence of results changes from “A” to ”Å” or vice versa, a new section is added. Consequently, the NSFetchResultsController's
sectionIndexTitles returns an array
("\U00c5", A, "\U00c5", A, "\U00c5", A, B, C, …)
and the section index titles look like this in my UITableView
:
Question: How can I make it so that names that start with letters that sort together only result in a single section?
Removing diacritical marks from the underlying data that are used to sort is not an option because some other locales treat ”A” and “Å” as separate letters, with “Å” sorted after “Z” in the alphabet.
A NSSortDescriptor
with a custom comparator is not an option because Core Data can only use a fixed set of built-in comparators. (This is because they are being translated to SQL for the underlying database.)