A subclass of NSManagedObject needs to observe some stuff.

So, in -awakeFromFetch and -awakeFromInsert, I invoke an -initializeObservers 
method which adds observers like this…

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(fooNote:)
                                             name:@“fooIt”
                                           object:self] ;               

And then in -willTurnIntoFault, and also in -didTurnIntoFault, I remove such 
observers

[self removeObservers:nil] ;

* * *

This normally works OK, but in some edge cases which I’ve not been able to 
reproduce but have analyzed by poking around with the debugger, the fooNote: 
selector does not get invoked as expected when a qualifying notification (name 
= fooIt, object = that object) is posted and I wait for coalescing.  If I 
release this object and re-fetch it from the store, notifications start working 
again.

I’m thinking this could happen if maybe -willTurnIntoFault ran for some reason, 
but then object was brought back to life somehow without -awakeFromFetch 
running.

Is that possible?  Am I using the correct design pattern for adding and 
removing observers?  Is it completely bullet-proof?

Thanks,

Jerry Krinock


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to