0
votes

I am currently implementing a UITableViewController with an NSFetchedResultsController. It fetches some objects from CoreData and displays them as rows in one section as expected.

Now, I would like to have one additional section with exactly one row that displays aggregated information about the fetched objects.

From what I know, one NSFetchedResultsController can only have one fetch request, but I would have to use another one to get the aggregated information.

Perhaps I should use one NSFetchedResultsController for the Overall section and another one for the single object section, but this feels kind of strange to me.

What do you think?

2

2 Answers

0
votes

You may consider to use one fetchedResultController. And add some observer functions in the delegate of fetchedResultController:

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller{
[self updateAggregatedInformation : basedOnFecthedObjects]; //with collection keypath methods;
[self updateTableView];

}

There is a little overhead in the tableView DataSource, but gain in performance.

0
votes

I just solved the problem and it was more easy than I thought.

The NSFetchedResultsControllerDelegate receives messages from the FRC and so the delivered IndexPath.section attributes have be adapted according to the tableView. The same needs to be done the other way around when the tableView calls the FRC to create cells that are backed up by the fetched entities.