1
votes

I am trying to use a nsfetchedresultscontroller to fetch objects from the DB for display in a tableview. I would like to append some custom objects to the fetched objects for displaying purposes. What would be the best way to do this?

My current method is to store [fetchedresultscontroller fetchedObjects] in a array called objectsDatasource and append my objects to it. I use this objectsDatasource as the datasource to the tableview. When I receive controllerDidChangeContent, I call fetchedObjects again and reload my objectsDatasource. Will there be any performance issue?

Alternative is to abandon nsfetchedresultscontroller and create my own array and add observer to the NSManagedObjectDidSaveNotification.

Does [fetchedResultsController fetchedObjects] fetch all the objects as faults initially and only fire the fault when the property is accessed?

1

1 Answers

1
votes

I will avoid copying the array returned from the fetch results controller and keep my added results in a seperate array when possible (the array returned from the fetch results controller is a virtual cursor to the actual data stored in the DB, and might not actualy hold the entire dataset in memory).
if the aditional items are not mixed with the results returned from the fetch results controller, i would might even put them in their own section of the table.

Does [fetchedResultsController fetchedObjects] fetch all the objects as faults initially and only fire the fault when the property is accessed?

This depends on the fetch request assigned to the fetch results controller. if you set: [request setReturnsObjectsAsFaults:NO] and [request setIncludesPropertyValues:YES], the controller will fault object as they are first fetched from the DB and not again when they are faulted (much beter performance).