0

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".

memmons
  • 40,222
  • 21
  • 149
  • 183

1 Answers1

0

From the NSFetchedResultsController docs:

You create a subclass of this class if you want to customize the creation of sections and index titles. You override sectionIndexTitleForSectionName: if you want the section index title to be something other than the capitalized first letter of the section name. You override sectionIndexTitles if you want the index titles to be something other than the array created by calling sectionIndexTitleForSectionName: on all the known sections.

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • So, you are saying I sort sections in an NSFetchedResultsController by...sorting sections in an NSFetchedResultsController? Very metaphysical. – memmons Dec 05 '10 at 16:44
  • Prior to 4.2 there was hardcoded sort that sorted alphabetically on the first letter of the sectionNameKeyPath. In 4.2, it takes the first provided sort. If you wish to override either of these default behaviors you must override the FRC methods above to provide your own behavior. – TechZen Dec 10 '10 at 19:25