Quentin
Quentin

Reputation: 1781

Update sectionNameKeyPath in an existing NSFetchedResultsController

I have a collection view populated with a NSFetchedResultsController. My collection view has sections (the NSFetchedResultsController is configured with a sectionNameKeypath) I need to apply various sorts. To do this, I modify the fetch request of my NSFetchedResultsController and I launch another performFetch.

self.myResultsController.fetchRequest.sortDescriptors = @[myNewSortDescriptor];
[self.myResultsController performFetch:&error];

For each sort, the section name keypath should be updated (if I sort by name, sections should be relative to name, If I sort by city, sections should be relative to cities). But I do not know how to modify section name keypath of an existing NSFetchedResultsController. Should I create a new NSFetchedResultsController at each sort change ?

Regards, Quentin

Upvotes: 2

Views: 400

Answers (1)

Wain
Wain

Reputation: 119031

Yes, create a new fetched results controller if you need to change the section name key path. If the FRC uses a cache be sure to delete that too.

Upvotes: 1

Related Questions