Re: KVO notification not properly propagated isuse
Re: KVO notification not properly propagated isuse
- Subject: Re: KVO notification not properly propagated isuse
- From: Quincey Morris <email@hidden>
- Date: Sun, 15 Mar 2009 21:22:13 -0700
On Mar 15, 2009, at 14:02, Marc Van Olmen wrote:
And then the above KVO worked. So I'm curious now why I need to add
[super observeValueForKeyPath: theKeyPath ofObject:theObject change:t
Because the documentation doesn't say anything about that. Is there
a documented reason when you have to call [super
observeValueForKeyPath ...]?
It's sort of obvious when you think it through. If you subclass an
object, and your subclass adds itself as an observer of something, the
superclass code may *also* have added itself as an observer of
something. Both scenarios result in the *same*
observeValueForKeyPath... being called.
Therefore, your observeValueForKeyPath... override must first check if
the notification is the one you established. If it is, you process it
and return without calling [super observeValueForKeyPath...]. If it is
not, you simply call [super observeValueForKeyPath...].
How do you decide if the notification is for you instead of the
superclass? That's a small hole in the API. To deal with it, you'll
have to set the context parameter to something unique to your subclass
(such as its name), and check the context in observeValueForKeyPath...
to decide if your code "owns" the notification or if the superclass
does.
This is obviously not ideal, and makes your observeValueForKeyPath...
override fairly ugly, but there it is ...
_______________________________________________
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