Re: KVO returning nil for old values, and mmalc's Graphics Bindings example
Re: KVO returning nil for old values, and mmalc's Graphics Bindings example
- Subject: Re: KVO returning nil for old values, and mmalc's Graphics Bindings example
- From: Tim Lucas <email@hidden>
- Date: Thu, 19 May 2005 23:50:53 +1000
On 18/05/2005, at 9:55 PM, Tim Lucas wrote:
Did anybody figure out why in mmalc's Graphics Bindings example he had
to to the following workaround, because KVO wasn't returning the old
values?
Quoting "Graphics Bindings" example, GraphicsView.m,
observeValueForKeyPath:ofObject:change:context:
/*
Should be able to use
NSArray *oldGraphics = [change objectForKey:NSKeyValueChangeOldKey];
etc. but the dictionary doesn't contain old and new arrays...??
*/
I have come across exactly the same problem.
I have 4 different set of KVO's being registered within my view's
bind: method, and only the first one will return the old values in the
change dictionary when a change is observed, the other 3 return nil,
even though all the KVO registrations look like this:
To follow up to this, I made an interesting observation.
Whilst observing something using KVO, when notified of a change the old
value is only returned if the new value object != the old value object.
If it is the same object then the change dictionary will contain nil
for the old value.
Although this makes complete sense in hindsight, as KVO can't store the
'state' of an object, its not exactly obvious behaviour.
Still not sure why mmalc's code wouldn't work... maybe the
NSArrayController's arrangedObjects is being reused, so its not
actually a new NSArray object...
Unfortunately I don't have time to follow up on this at the moment, but
if anybody has any more info i'd love to hear it...
- tim lucas
_______________________________________________
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