Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
- Subject: Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
- From: Jerry Krinock <email@hidden>
- Date: Sat, 30 Jan 2010 10:33:52 -0800
On 2010 Jan 30, at 09:12, Keith Duncan wrote:
>>> Why are bindings A, B, C and D bidirectional but E is only unidirectional?
>>
>> Regarding A, B, C and D: Apparently, NSButton's implementation of bind:::: sets up observers in both directions when binding to the "value" binding.
>
> This isn't what happens, run the following code:
My Time Manager says I should take your word for it on that :>
> What NSButton does when it needs to change the value of it's bound to counterpart, is introspect the binding either through -infoForBinding: (or other means depending on where it stored the captured binding information, we'll assume the -infoForBinding: case for simplicity).
>
> It extracts the bound-to object (stored under NSObservedObjectKey), and the keypath (stored under NSObservedKeyPathKey) and invokes [observedObject setValue:newValue forKeyPath:observedKeyPath].
Ah, indeed, it would be rather inefficient to tell someone else to observe your changes, call you back and get a value. Instead, just activate a branch in your own setter to push your changes out when one occurs.
That makes much more sense, and also gives another reason why this is not generally referred to as a "bidirectional" or "two-way" binding. That implies symmetry, when in fact the mechanism in the two directions is quite different.
Good work, Keith.
_______________________________________________
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