Re: Observing NSArrayController's content, shouldn't it be simple ?
Re: Observing NSArrayController's content, shouldn't it be simple ?
- Subject: Re: Observing NSArrayController's content, shouldn't it be simple ?
- From: Chris Hanson <email@hidden>
- Date: Mon, 7 May 2007 23:37:20 -0700
On May 7, 2007, at 1:06 AM, Yann Bizeul wrote:
What I want to do is quite simple, I just want to register as an
observer for A's content, and get added/removed values.
So I do register like this :
[A addObserver:self forKeyPath:@"content" options:
NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld
context:nil];
And I'm listening like this :
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:
(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"%@",change);
}
But all I get each time I add an object is :
{kind = 1; new = <null>; old = <null>; }
While it may be a bug that you're not receiving the old/new values
that you asked for in the change dictionary, you are still getting a
correct notification for the change itself. An
NSKeyValueChangeKindKey (kind) value of NSKeyValueChangeSetting (1)
means that the property you're observing changed.
Note that what you set out to do -- and what is actually being done --
is observe A's "content" property. When the "content" property of A
is changed to something else, you'll get the behavior you're seeing.
(And, as I said above, you might also legitimately expect to receive
the old and new values in the change dictionary.)
If what you really want to observe changes to the *value* of whatever
A's "content" property is, then you should observe it directly. For
example, if A's "content" property is an array or set, you can observe
that array or set itself in order to be notified of its mutations.
This might work better as a diagram:
A --> content --> something
You're looking at "content" and getting notified that it's
(effectively) being set each time "something" changes. But what you
seem to be really interested in are finer-grained changes to
"something" so you should observe it instead.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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