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:
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?
In general, NSFetchedResultsController is designed to respond to changes at the model layer, by informing its delegate when result objects change location or when sections are modified.
NSFetchedResultsController is a very useful class provided by the CoreData framework. It solves many performance issues you frequently run into while reading a large amount of data from database and displaying that data using a UITableview, UICollectionView or MKMapView.
An object space to manipulate and track changes to managed objects.
A description of search criteria used to retrieve data from a persistent store.
just have your problem and yes apparently using notifications is the unique way you can make a tableview refresh when the table used a nsfetchedresults controller.
like in the core databooks sample:
step1: add an observer to the NSNotificationCenter for the notification NSManagedObjectContextDidSaveNotification
step2: save your context (the notification trigger to your selector)
step3: in your selector method: merge the changes in the context using the method mergeChangesFromContextDidSaveNotification
step4: remove the observer from the notification center.
Personally I would like to bypass the notification certer and only tell the context refresh yourself dammit :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With