I am removing the persistentStore from a persistentStoreCoordinator at some point in my application (and loading another store) and reset
my managedObjectContext.
When I do that, according to the documentation, I also need to delete all references to managedObjects that have been fetched:
All the receiver's managed objects are “forgotten.” If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver,
since they will be invalid afterwards.
I would like to avoid having to go through all my fetchedResultsControllers, caches, arrays that may contain managedObjects, detail views that also store an object, etc.
Instead I'd prefer to observe if the managed object's isInserted
status changes. Something like
[myObject addObserver:self
forKeyPath:@"isInserted"
options:0
context:nil];
Unfortunately this doesn't seem to work.
So – how can I observe if a NSManagedObject is removed from managedObjectContext?