Database Reference
In-Depth Information
-controllerDidChangeContent:
The final method tells us that this round of changes is finished and we can
tell the UITableView to update the user interface. We can also use this method
to update any other parts of the user interface outside of the UITableView . For
example, if we had a count of the number of recipes displayed, we would
update that count here.
RecipesV1/PPRecipes/PPRMasterViewController.m
- ( void )controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[[self tableView] endUpdates];
}
With the implementation of the five methods described earlier, our UITableView
can now retrieve, display, and update its display without any further work
from us. In fact, a large portion of the code in the NSFetchedResultsControllerDelegate
methods is fairly boilerplate and can be moved from project to project, further
reducing the amount of “new” code we need to maintain.
2.2
Under the Hood of the NSFetchedResultsController
We can see the value of an NSFetchedResultsController , but how does it actually
work? When I started to explore the details, I was shocked to find out that I
could duplicate much of the behavior of the NSFetchedResultsController using
publicly available APIs.
At its core, the NSFetchedResultsController takes advantage of the notifications that
an NSManagedObjectContext fires off. When we initialize the NSFetchedResultsController ,
it sets itself up as an observer and then reacts as the notifications come in.
NSManagedObjectContextObjectsDidChangeNotification
One of the three notifications that the NSFetchedResultsController listens for is the
NSManagedObjectContextObjectsDidChangeNotification . This very chatty notification tells
the NSFetchedResultsController whenever one of the attributes of any object has
changed. The NSFetchedResultsController uses this information, combined with its
NSFetchRequest , to determine whether it needs to notify its delegate of the
changes. Changes of this type often result in a call to -controller:didChangeObject:
atIndexPath:forChangeType:newIndexPath: , with a change type of NSFetchedResultsChange -
Update and/or NSFetchedResultsChangeMove .
NSManagedObjectContextWillSaveNotification
Without access to the source code of the NSFetchedResultsController , I can't say
with 100 percent certainty that this notification is used; however, it appears
 
 
 
Search WWH ::




Custom Search