On Dec 12, 2008, at 22:19, Bridger Maxwell wrote:

I have a custom view subclass (sineWaveView) that the user interacts with to change a property (connectedContact). I would like to bind this to a value (selectedShortRangeContact) in a dictionary (database) in another object (databaseClient). Simple, right? Anyway, I establish the binding like so:

[sineWaveView bind:@"connectedContact" toObject:databaseClient withKeyPath:@"database.selectedShortRangeContact" options:nil];

This question gets asked often enough that it should be in a FAQ somewhere...

[NSObject bind:toObject:...] does *not* define a binding, but just establishes an already-defined binding between objects. The binding definition is a collection of behaviors plus an exposed binding name. To use a custom binding, you must first define this behavior, giving it a binding name (which is *not* a key or key-path). Then you establish the binding using that name as a parameter to [NSObject bind:toObject:...].

If you go ahead and use a key as the binding name, you get the one-way limited behavior you saw, but it really should produce an error since it's not really working as a binding.

How do you define the behavior of a binding? Well, an example is described in:

        
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html

The value of bindings is their ease of use in IB. Programmatically, defining new bindings is probably more trouble than it's worth -- you may as well just program the observer behavior you want directly.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to