I have a core data app that is using the sectionNameKeyPath “group.name” with the fetchRequest in order to group the results by the group entity’s name attribute. I’m grouping by group.name but I’d like to sort the sections by something other than group.name. According to the NSFetchedResultsController docs:
If the controller generates sections,
the first sort descriptor in the array
is used to group the objects into
sections; its key must either be the
same as sectionNameKeyPath or the
relative ordering using its key must
match that using sectionNameKeyPath.
Which means that the sections must be sorted in the same order the are grouped in. Despite the documentation, prior to iOS 4.2 you could get away without specifying the sectionNameKeyPath as the first sort descriptor which allowed you to sort the sections, but no longer.
What is the best way to sort sections in an NSFetechedResultsController? For example, I want my sections to be grouped by “group.name” but sorted by “group.timestamp”.
From the NSFetchedResultsController docs: