Re: KVO with Proxy Classes
Re: KVO with Proxy Classes
- Subject: Re: KVO with Proxy Classes
- From: Mike Rossetti <email@hidden>
- Date: Thu, 3 Feb 2005 18:44:25 -0700
Okay, I figured it out. It was indeed that the view in Window A was observing a different object than Window B was controlling, and it was because I was only creating the proxy objects as needed. Further, my model was using a vector<person> while the observers were using a reference to person but when the vector would grow to a certain size it would get reallocated, all of the person's would get copied, and the original person instances would no longer be valid.
I've switched to shared_ptr<person> in place of just person and the problem has gone away.
Thanks for listening,
Mike
On Feb 2, 2005, at 9:53 PM, Mike Rossetti wrote:
Hello Cocoaholics,
Imagine Window A with a list of people. Select a person and press the Edit button and Window B is presented with details about the selected person. Changing the person's name and tabbing to the next field causes the person's name in the list in Window A to update.
This is all being done with bindings. Window A has an array controller wired to the data model. Window B has an object controller wired to the window's data source.
Everything works fine when my data model is based on an NSMutableArray (people) which contains NSObjects (a person). That is, typing a change in the name in Window B and tabbing causes Window A to update immediately.
But when I turn the NSMutableArray into a proxy (i.e. I intercept count, objectAtIndex:, etc. and manage the data out of a secondary object (in this case vector<person>)) and provide an ephemeral proxy object to provide the KVC/KVO interface (an NSObject subclass with forwarding functions such as setPersonName, getPersonName)...
...the result is that a change in the name in Window B (the person edit window) is only reflected in Window A after closing Window B.
I tried wrapping the name changing code within setPersonName in willChangeValueForKey:/didChangeValueForKey: but that made no difference.
I suspect that the creation of these person proxy objects only when needed may break some link between the person edit controller and the observed.
Any thoughts on the matter would be most appreciated.
Thanks,
Mike
_______________________________________________
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