I have a multi-context core data application that uses observers heavily to keep the UI in state. I'm running into a crop of deletion problems that occur because an observed object is deleted. I would love to guard my observers with 'if ([mo isDeleted]) return;':
From NSManagedObject documentation
The method returns YES if Core Data will ask the persistent store to delete the object during the next save operation. It may return NO at other times, particularly after the object has been deleted. The immediacy with which it will stop returning YES depends on where the object is in the process of being deleted.
So ok, terrible design choice in my book, but I'm curious as to how people work around this. Obviously I need to clear out observed properties prior to deletion. Only "Clean" way I can think to do this is to observe NSManagedObjectContextWillChange events and see if I am storing any of the deleted objects. Seems like a clean work around, but maybe I'm missing something.
Another alternative that may or may not work with your design: -[NSManagedObject managedObjectContext]
will return nil
if it has been deleted and the context has been saved. You could check for this after an NSManagedObjectContextDidSave
notification.
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