• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to set up manual bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: How to set up manual bindings
      • From: mmalcolm crawford <email@hidden>
    • Re: How to set up manual bindings
      • From: mmalcolm crawford <email@hidden>
References: 
 >How to set up manual bindings (From: René Puls <email@hidden>)

  • Prev by Date: Strange thing when using NSProgressIndicator
  • Next by Date: Re: static objects "autoreleased with no pool in place - just leaking"
  • Previous by thread: How to set up manual bindings
  • Next by thread: Re: How to set up manual bindings
  • Index(es):
    • Date
    • Thread