Hey!
I need something like an opposite to NSManagedObjectContextObjectsDid
ChangeNotification. Something like NSManagedObjectContextObjectsWill
ChangeNotification. I think this would solve this problem (stackoverflow-question).
It's importent that it notificates before it deletes the object (in that problem) for changing the selected NSMenuItem early enough. ;)
-
I don't think it's possible to be notified before an object is deleted. However, in the
userInfo
dictionary forNSManagedObjectContextObjectsDidChangeNotification
there's a key calledNSDeletedObjectsKey
which will give you all the objects that have been deleted. Now, the word "deleted" is a little complicated here, since these objects have technically only been marked for deletion. Their attributes are still accessible to you if you happen to need them for some reason.As for your other problem, I think the person who answered that question is right. You should be looking at the
NSArrayController
you've bound the popup button to, not the popup button itself. It has to do with how you delete the object. If you're doing it right, the popup button will observe the deletion automatically. Your problem has to do with bindings, not Core Data, it would seem. -
If your application is 10.6 only, check out [NSManagedObject prepareForDeletion] in the Apple docs. Another possible approach is to implement "validateForDelete:" on NSManagedObject. This gets called during the validation stage when a context gets saved. Be sure to call through to super as part of your implementation.
0 comments:
Post a Comment