The acquired object in index 501 has the name of the section outside the order "APPLIED PHYSICS MAGAZINE". Objects should be sorted by section name '

I have a database of articles with journal section names. One article is the Journal of Applied Physics, and another is the Journal of Applied Physics. When i use

[[NSSortDescriptor alloc] initWithKey:@"Journal" ascending:YES elector:@selector(caseInsensitiveCompare:)]

to get the data, he gives me an error message.

The fetched object at index 501 has an out of order section name 'JOURNAL OF APPLIED PHYSICS. Objects must be sorted by section name'

I already use case insensitive, so why doesn't this work? Help?

======= code used to retrieve data =======

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Article" 
                                          inManagedObjectContext:SharedMOC];

[fetchRequest setEntity:entity];

NSSortDescriptor *journalSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Journal" 
                                                                     ascending:ascending 
                                                                      selector:@selector(caseInsensitiveCompare:)];

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:journalSortDescriptor,  nil];

[fetchRequest setSortDescriptors:sortDescriptors];

NSFetchedResultsController *a = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                                                    managedObjectContext:SharedMOC 
                                                                      sectionNameKeyPath:[self selectedSortSection]
                                                                               cacheName:cacheName];
+3
source share
1 answer

My intuition says that instead of:

[fetchRequest setSortDescriptors:[self getSortDescriptor]];

You must write:

[fetchRequest setSortDescriptors:sortDescriptors];
+1
source

All Articles