Re: bindings and sub array modification notification.
Re: bindings and sub array modification notification.
- Subject: Re: bindings and sub array modification notification.
- From: Quincey Morris <email@hidden>
- Date: Sun, 18 Jan 2009 20:37:56 -0800
On Jan 18, 2009, at 17:02, Sandro Noel wrote:
How could I possibly observe the changes in the information array or
each host element?
or if no possible, the currently selected host...
I currently have an observer on the hosts array, and that works when
the array is changed(added/deleted),
but i would need to get notification when the content of a "host" is
also changed.
is that possible ?
There's no magic involved. Your observer has to say it wants to
observe, with object/key-path granularity:
[host addObserver: self forKeyPath: @"firstProperty" ...];
[host addObserver: self forKeyPath: @"secondProperty" ...];
...
Repeat for each host (as you add it to the array of hosts, for example).
Of course, in many cases you don't need or want to set up systematic
observations of all properties of all objects like this*. In many
cases, observations result from the use of bindings. When you use a
binding in IB (from, say, a NSTableColumn), adding itself as an
observer is one of the things that the observing UI element does for
itself, and supporting bindings by watching for the comings and goings
of objects in array properties is in fact the fundamental purpose of
the NSArrayController class.
BTW, you don't "have an observer on the hosts array", you have an
observer on the "hosts" property of the object that owns the hosts
array. If you religiously train yourself to think and speak in terms
of (owning) object *having* a property instead of (value) object
*being* a property, you'll save yourself a lot of grief.
*One good reason for systematically observing all properties of all
objects in your data model is automatic invocation-based undo.
_______________________________________________
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