• 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 - Observing self from self
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO - Observing self from self


  • Subject: Re: KVO - Observing self from self
  • From: Joakim Danielson <email@hidden>
  • Date: Sun, 2 Jul 2006 11:25:26 +0200

Why don't you use setKeys:triggerChangeNotificationsForDependentKey: ?

http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/index.html#//apple_ref/doc/uid/10000177i


Joakim

1 jul 2006 kl. 17.43 skrev Daniel Jalkut:


I'm using KVO to observe a keypath relative to "self." For example, I'm observing "myTree.apples" from an object with a keyed object "myTree."


This is very convenient because it means I don't have to carefully manage the addObserver/removeObserver status as "myTree" changes. But I've noticed that KVO, in an attempt to protect me from "bad stuff" actually limits my ability to use this technique.

In the object's "dealloc" method, it removes observation of itself. This should have the effect of cleaning everything up, right? But apparently KVO interferes much earlier - detecting my impending dealloc and warning me about the fact that there is still an observer:

An instance 0x38f6a0 of class CueSpecifier is being deallocated while key value observers are still registered with it. Break on _NSKVODeallocateLog to start debugging.

What's worse, is it apparently then removes the observer for me, so that when my responsible "self cleanup" occurs moments later, I see this in the console:


Exception ignored while releasing an object in an autorelease pool: [<CueSpecifier 0x38f6a0> removeObserver:<CueSpecifier 0x38f6a0> forKeyPath:@"cueHandler.parameterMenuItems"] was sent to an object that has no observers.

I guess this is tricky because KVO's watch-dogging is happening at the sneaky isa-swizzling level.


What are my options? Does anybody have a clean solution for observing self keypaths from self? I could figure out some way to manually remove observation before being dealloc'd, but at that point the convenience factor pretty much disappears.

Daniel

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: KVO - Observing self from self
      • From: Daniel Jalkut <email@hidden>
References: 
 >KVO - Observing self from self (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Changing file & directory names
  • Next by Date: Shiny little square buttons
  • Previous by thread: KVO - Observing self from self
  • Next by thread: Re: KVO - Observing self from self
  • Index(es):
    • Date
    • Thread