So, I played with this particular situation, and I will not contradict the first answer - you probably shouldn't do this, and if you need it, iCloud might work. Do not use this code. I provide it to help others get to the point that they can detect all the problems that I have not fixed, and move on.
However, you can do what the original question wanted to ask - to force the controller to reboot from disk:
// Tear down bindings and context, create new context & rebind [self.watcherAC unbind:@"managedObjectContext"]; [self saveAction:self]; // Optional, dependent on NSMergePolicy, etc self.managedObjectContext = [[NSManagedObjectContext alloc] init]; self.managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy; [self.managedObjectContext setPersistentStoreCoordinator:self.persistentStoreCoordinator]; [self.watcherAC bind:@"managedObjectContext" toObject:self withKeyPath:@"managedObjectContext" options:nil]; // Force controller to refetch and rearrange NSError* error; [self.watcherAC fetchWithRequest:nil merge:NO error:&error]; // Immediate fetch [self.watcherAC prepareContent]; [self.watcherAC rearrangeObjects];
This updates the contents of the tableView from storage on disk. (TableView is bound to watcherAC array controller)
I found that fetch: is not immediate - this was done the next time through the launch loop for the application. So that the fetch / swap is done in the correct order, you need to use fetchWithRequest:
I'm not sure if readyContent: is needed, although it may have helped fix errors in the contents of the controller.
I was not able to get it to restore the selection of tableView, although it may be because I am doing this in a delegate call to tableview, so the choice of the view does not synchronize with the choice of the controller no matter what attempts I try. Maybe this might work for someone, but I suggest trying to figure out how not to allocate a new MOC if your view has bindings to it.
source share