• 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
Re: KVO: when to stop observing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO: when to stop observing?


  • Subject: Re: KVO: when to stop observing?
  • From: Jerry Krinock <email@hidden>
  • Date: Sun, 30 Aug 2009 11:13:10 -0700


On 2009 Aug 29, at 23:59, Michel Schinz wrote:

I'm therefore looking for better solutions, and would be interested to know what people have come up with.

I believe the best answer to the question of "when to stop observing" is "as soon as possible".


I was having trouble with a Core Data document (NSPersistentDocument) observing too long, until I started cleaning things like this up in - [NSDocumentController removeDocument:]. See typical code below.

You should also scroll down in your mailbox and read the thread which was still active yesterday, "Re: Get error message about registered observers when Object receives dealloc message". There is a good discussion of this issue.

In the implementation of my subclassed NSDocumentController....

- (void)removeDocument:(NSDocument *)document {
// Remove observations by document's window controller
[[MAKVONotificationCenter defaultCenter] removeObserver: [(Bkmslf*)document bkmslfWinCon]] ;
[[NSNotificationCenter defaultCenter] removeObserver: [(Bkmslf*)document bkmslfWinCon]] ;


    // Remove observations by document itself
    [[NSNotificationCenter defaultCenter] removeObserver:document] ;
    [[MAKVONotificationCenter defaultCenter] removeObserver:document] ;

[SSYMOCManager removeManagedObjectContext:[(Bkmslf*)document managedObjectContext]] ;

    [super removeDocument:document] ;
}


_______________________________________________

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


References: 
 >KVO: when to stop observing? (From: Michel Schinz <email@hidden>)

  • Prev by Date: Re: nsuserdefaults woes
  • Next by Date: Re: Async NSURLConnection + Concurrent NSOperation = Not possible under Mac OS X 10.6?
  • Previous by thread: Re: KVO: when to stop observing?
  • Next by thread: NSScroller width
  • Index(es):
    • Date
    • Thread