• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Removing object as observer in -willTurnIntoFault
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Removing object as observer in -willTurnIntoFault
      • From: Dado Colussi <email@hidden>
  • Prev by Date: Re: Removing a file via NSFileWrapper
  • Next by Date: Re: Removing object as observer in -willTurnIntoFault
  • Previous by thread: Re : Re: Removing a file via NSFileWrapper
  • Next by thread: Re: Removing object as observer in -willTurnIntoFault
  • Index(es):
    • Date
    • Thread