Removing object as observer in -willTurnIntoFault
Removing object as observer in -willTurnIntoFault
- Subject: Removing object as observer in -willTurnIntoFault
- From: Jerry Krinock <email@hidden>
- Date: Sat, 29 Mar 2014 11:13:41 -0700
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 (email@hidden)
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:
This email sent to email@hidden