Binding
Binding consists of a few different technologies and techniques. Accessing properties based on string “keys” is called Key-Value Coding (KVC).
Observing property changes using string “keys” is called Key-Value Observing (KVO).
More information can be found on these topics at the following URLs:
Terminology
Key
A string which is of the same name as an object’s property. Eg. age, name, value.
Key Path
A dot separated list of multiple keys. For example, if we had a Person object, structured as follows:
{name:String, mom:Person, dad:Person}
A key path to a person’s mom’s name would be.
person.mom.name
Making your Objects KVC Compatible
For binding to work with your code, you must use one of the following patterns. <key> is the name of the property. Type is the type of your property.
- Getter:
function <key>():Type;
or (note uppercased key)
function is<Key>():Type;
or (note uppercased key)
function get<Key>():Type;
- Setter (note the uppercased key)
function set<Key>(n:Type):Void;
If no accessor functions are found for the given key, we attempt to access an internal member named <key>.
Links
- Simple tutorial that shows how to use
NSArrayControllerwith an application. However, the author is working mainly with Xcode, and very little Objective-C code is used to implement the bindings.
http://www.macdevcenter.com/pub/a/mac/2004/04/06/cocoa.html
- A structured and step-by-step tutorial, with plenty of diagrams and screenshots. Again, mainly works with Xcode.
http://cocoadevcentral.com/articles/000080.php
- List of Cocoa binding examples. Those of exceptional interest include the Manual Bindings, Graphic Bindings and Combatants, which establishes bindings programmatically.
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
- Pure Objective-C tutorial on binding, however, it is in German.
Of particular interest would be the section Binding anbieten (no idea what that means) which explicitly uses+ exposeBindingsand- valueClassForBinding, because they’re are usually passed over due to the use of Interface Builder.
http://www.macentwicklerwelt.net/index.php?title=Cocoa_Bindings_%28Eigene_Bindings_anbieten%29
projects/actionstep/documentation/binding.txt · Last modified: 2007/02/19 08:11 by niko