NSFetchedResultsController secondary sorting not working?
- by binkly
Hello,
I'm using NSFetchedResultsController to fetch Message entities with Core Data. I want my tableview to group the messages by an attribute called ownerName. This works fine in the sense that I get a proper UI dispalying appropriately named sections. I can achieve this with the code below:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ownerName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *fetchedResultsController = nil;
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[appDelegate managedObjectContext]
sectionNameKeyPath:@"ownerName"
cacheName:@"Messages"]
What'd I'd like to do now is have the section with the newest message at the top; exactly how it works with the Messages app on iPhone currently.
I've tried adding a second sort descriptor and putting it in an array of sort descriptors and passing that to the fetchRequest but it doesn't appear to be affecting anything.
Here is the 2nd sort descriptor that I used.
NSSortDescriptor *idDescriptor = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:YES];
If anyone could provide some insight into this I would greatly appreciate it.