I'm working on an application that holds its data in an external MySQL server, but caches it locally using Core Data for better response times. Basically, what I'd like to do is this:
- Fetch data from Core Data (SQLite data store, using NSFetchedResultsController) and display it
- Grab new items from the MySQL server in the background
- Refresh the current table view with the new set of data (both new and old items)
I have all this working except the last step. I can't quite figure out how to make an NSFetchedResultsController update its set of data. So far, I've tried adding items directly to its NSManagedObjectContext:
[NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:[fetchedResultsController
managedObjectContext]];
I've also tried what Apple does in their CoreDataBooks example, and used a separate "adding" managed object context and a call to mergeChangesFromContextDidSaveNotification:
. Neither seems to change the set of NSManagedObject*s currently in my fetched result controller's managed object context.
How would I go about updating the set of objects an NSFetchedResultsController currently manages?