Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSManagedObject and isDeleted

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.

like image 499
Brian King Avatar asked Dec 09 '22 11:12

Brian King


1 Answers

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.

like image 101
Daniel Dickison Avatar answered Dec 31 '22 10:12

Daniel Dickison