views:

94

answers:

1

I'm reading now since one hour through the documentation and still don't get the point of NSFetchedResultsController. Is it a replacement for UITableViewController? Or is the UITableViewController using the NSFetchedResultsController? Is the NSFetchedResultsController the data source? What is it?

+4  A: 

NSFetchedResultsController bundles together all the Core Data fetch related functions you need to perform when providing data for a table. It encapsulates a lot of the common functions associated with tables so you don't have to manage them by hand. It serves as the software interface between a tableview controller and a Core Data based data-model.

Tableviews need data provided in structured list. They need to manage and display a lot of data. They need to update their displays when the data itself changes behind the scenes. NSFetchedResultsController assist all this by:

  1. In addition to all the ordering and sorting done by fetches, it fetches and manages sections automatically so you don't have to perform a separate fetch just for sections.
  2. It caches fetch results making the display of the table faster.
  3. It monitors the Core Data graph and notifies its delegate, usually the tableview controller, if the table needs to reload its data. This is very useful in situations such as loading data from a URL. If the data is constantly changing you have to constantly fetch and check the results if you don't use NSFetchedResultsController.

You don't have to use it. You can do all this by hand if you want to. If you do not use Core Data in your data-model, then you don't use it.

TechZen