Re: How to set up manual bindings
Re: How to set up manual bindings
- Subject: Re: How to set up manual bindings
- From: René Puls <email@hidden>
- Date: Fri, 13 Feb 2004 13:04:15 +0100
Hello everyone,
For those who don't remember what this was about, please see:
http://cocoa.mamasam.com/COCOADEV/2004/02/1/83036.php
Here are some more details on the manual bindings problem which I
posted here a few weeks ago. I filed a bug with Apple, and yesterday I
received a response. I think many of you will find this interesting,
since it gives some insight into the way bindings work in Cocoa:
This is the intended behavior. Bindings are only two-way if the view
supports it. Within the setFoo: method, the view should check for a
binding (which means that the bind:toObject:... method also has to be
overridden to track the existence and parameters of the binding) and if
present, invoke setValue:forKey: on the "controller" object it is bound
to.
I find this new information somewhat disappointing. Until now I thought
that bindings were a generic feature of Cocoa and could be used
anywhere to ensure that two values are always synchronized. It turns
out this is not the case.
Apparently you need to have special support (e.g. override
bind:toObject:) in at least one of the classes that takes part in the
binding. I am not sure I understand the reasons for this, because I
already managed to write a replacement function
simpleBind:toObject:withKeyPath:options: which creates my own kind of
binding that works with all objects and doesn't require special
support.
Please have a look at my updated example project:
http://home.kcore.de/~kianga/public/BindTest2.zip
This code works by creating a helper object for each binding. That
helper registers as an observer to both bound objects and synchronizes
their values as necessary. Keep in mind that this is just a
proof-of-concept implementation. It can't be used in real applications,
as it currently leaks one helper object per binding. Also it doesn't
support any of the options you can use with Apple's bind:toObject:...
function.
I don't think I really want to "go there" and write my own binding
replacement. I guess I'll just rethink the way I use bindings and
continue to use "conventional" program designs in that case. There are
probably reasons why Cocoa's bindings work the way they do, but Apple
could have made the limitations clearer in the documentation.
Kind regards,
Reni Puls
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.