According to apple documentation of NSFetchedResultsController:
You use a fetched results controller to efficiently manage the results
returned from a Core Data fetch request to provide data for a
UITableView object.
According to documentation of NSManagedObjectContext:
Its primary responsibility is to manage a collection of managed
objects.
It seems that purpose of these two classes overlap. Both “manage the fetched managed objects”. Maybe the difference of wording indeed mean something, yet I don’t get it. After reading both docs, it seems to me that all the data fetch, modify, commit, undo/redo etc. is handled by the managed context. I don’t see the point of nsfrc existing.
Could anyone explain why do we need fetched results controller when we already have managed context to deal with data?
The
NSManagedObjectContextis a fundamental concept of Core Data, kind of analagous to a transaction in a relational data. Not only can you fetch objects, you can create, update and delete them, save them back to the persistent store, etc.You don’t need the
NSFetchedResultsController. It’s a utility class, one designed to provide Core Data objects in a format that’s easily usable in a table view. The fetched objects used in anNSFetchedResultsControllerwill be managed by anNSManagedObjectContext.Having said that, “utility class” seriously undersells it. It automatically manages things like updates, inserts and deletes in the underlying data source, caching, sections, etc., things that are a pain to deal with manually.