CoreData: error: (NSFetchedResultsController) The fetched object at index 72 has an out of order section name 'อั. Objects must be sorted by section name'
I am using the following code to sort by book title field and display book title's first upper case letter as the section name in a UITableViewController.
The code runs perfectly in all languages except of Thai. I read on the Internet that there are special non US characters causing such issues (i.e. Æ), but I didn't find any solution yet.
See gschandler response on The fetched object at index [i] has an out of order section name 'å
Code of FRC is
NSFetchedResultsController *aFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:managedObjectContext
sectionNameKeyPath:@"titleFirstLetter"
cacheName:nil];
Code of firstLetter is:
- (NSString *)titleFirstLetter {
// support UTF-16:
NSString* val = [self.title substringWithRange:[self.title rangeOfComposedCharacterSequenceAtIndex:0]];
return [val uppercaseString];
}
Any suggestions?
You have to add a sort descriptor that sorts on the same property the sectionNameKeyPath does.
NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"titleFirstLetter" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort,nil]];
[fetchRequest setFetchBatchSize:20];
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