I have an app that fetches data (a list of countries) from an sqlite database. The countries are in German and contain umlauts, for example Österreich. I want to fetch those countries sorted by name and would expect Österreich to be near other countries with "O", but it is at the end of the results instead.
This code is used to fetch the sorted countries:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: [NSEntityDescription entityForName: @"Continent" inManagedObjectContext: moc]];
[fetchRequest setSortDescriptors: [NSArray arrayWithObject: [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES] autorelease]]];
NSError *error = nil;
NSArray *result = [moc executeFetchRequest: fetchRequest error: &error];
Is there any way to have those special char names appear at the position I described above? Didn't find anything on the internet on this ...
Thanks a lot.
Thanks for your answers, I could solve the problem another (easy) way!
I just had to modify the NSSortDescriptor like this:
[NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES selector: @selector(localizedCompare:)]
You should use UILocalizedIndexedCollation for doing sorting and categorizing entries into sections. The code for implementing this is in the question NSFetchedResultsController v.s. UILocalizedIndexedCollation
The UILocalizedIndexedCollation was built to be able to on a per-language basis categorize words based on the current language settings. Á and à will be put in section A.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With