Re: Cocoa bindings one- or bi-directional
Re: Cocoa bindings one- or bi-directional
- Subject: Re: Cocoa bindings one- or bi-directional
- From: Kay Roepke <email@hidden>
- Date: Fri, 27 May 2005 14:04:03 +0200
On 27. May 2005, at 4:39 Uhr, mmalcolm crawford wrote:
This is correct behavior. You tell brick1 to observe changes on
the keypath intValue of the object brick2.
This is at best misleading. The code specifies binding, not
observing. The basic goal of binding is to keep two values
synchronised. If you use the bind:... method to bind a text
field's 'value' to a keypath in an object controller, you could get
the expected behaviour.
Point taken...
brick2 doesn't know anything about brick1
brick2 knows enough about brick1 to send KVO notifications when
intValue changes...
but the actual implementation of brick2 doesn't? I thought this was
"added onto brick2" by way of isa-swizzling and/or other means?
So I guess what I should have said next, wasn't
- that wouldn't be really helpful, would it?
... it would be helpful if the two were synchronised as expected ...
but rather: 'You'd just asked brick1 to bind to brick2's intValue,
but said nothing about the other way round. Silently
binding both objects together would do more than you asked to.'
The issue here is that binding is "one-way" if you only use the
behaviour you get for free. You can bind a KVC-compliant attribute
of any object ("object A") to the property of another object
("object B"), and object A will register as an observer of the
property of object B and update its (object A's) attribute in
response to changes in the observed property value. What it won't
do, however, is to push changes the other way -- that is, by
default you have in effect a "read-only" binding. If object A's
attribute value is changed, object B is not updated. To get this
behaviour, you must write custom code -- see:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/HowDoBindingsWork.html>
The way bindings are implemented tempted me to the hiccup of mixing
binding/observing in my first post. Sorry 'bout that.
Kay
_______________________________________________
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