I have RestKit 0.23.0 with Core Data and NSFetchedResultsController in my project. I want to change an attribute of an entity and reload my view in - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
.
I get the managed object that I want to change from objectManager.managedObjectStore.mainQueueManagedObjectContext
, change the attribute and call objectManager.managedObjectStore.mainQueueManagedObjectContext saveToPersistentStore:&error]
. The controllerDidChangeContent
method is called, but the data is not written to the database at that time.
After debugging in NSManagedObjectContext+RKAdditions.m
, I saw that success = [contextToSave save:&localError];
is called two times. The first run fires controllerDidChangeContent
(data is not written to the database at that time) and the second call writes the data to the database, but does not call controllerDidChangeContent
.
Any ideas what I did wrong?
There is nothing 'wrong', you are just seeing 2 different stores being saved. First the main thread store (non-persistent) and then the persistent store (backed on disk). The main thread store is a child of the persistent store.
So, you get a notification when the main thread store is saved, because that is what you asked for, but the persistent store hasn't been saved yet so nothing has been saved to disk.
This should not cause you a problem. If it does you either have a logical error in your code or your approach to solving the problem isn't quite right.