KVO: Is it possible to remove all observers from a specific object?

I use key monitoring. I have object_1 (NSManagedObject) and several other observer objects. When I remove object_1 from the context of a managed object, my program crashes.

CoreData: Error: A serious application error. An exception was found during the processing of changes to Core Data. This is usually an error in the NSManagedObjectContextObjectsDidChangeNotification observer.

Is it possible to put something in the dealloc method (or in another place) to remove all observers of object_1? Or is the only suitable solution to send a notification when I am going to remove object_1 from the context of the managed object and listen to this notification with other objects (to remove myself from the observers of object_1)?

+7
source share
1 answer

You need to ensure that your observers are deleted before your object is released. This is a lack of observer key values.

As you suggest, one way to do this is to delete, called from your dealloc method. Obviously, you may not know who has observers at your facility, but you still need to notify them.

I would describe what you need to do, but maybe just bj-homer look at the answer to the question When do I need to remove observers? Error deleting objects before deleting observers .

If this is what you need, then just vote. If not, vote here. Hope this helps.

+7
source

All Articles