How can I write cocoa bindings as code instead of in the Interface Builder?

Posted by johnjohndoe on Stack Overflow See other posts from Stack Overflow or by johnjohndoe
Published on 2010-06-02T21:36:35Z Indexed on 2010/06/02 21:44 UTC
Read the original article Hit count: 250

In my modell got an NSMutableArray that keeps track of a changing number of elements. In my view I got a NSTextField that shows the number of elements. The view gots unarchived from the nib file and alloc/inits the modell. Therefore it knowns about the modell and the contained array.

I established the connection as follows. In the Interface Builder at the textfield I added a Cocoa Binding "path" like this: myModell.myArray.@count. By this I can access the count property (which is a must since the array itself does not change). The binding is based on key-value compliance which I established at the modell so the array can be accessed. But key-value compliance is not part of the questions.

My question: How can I put the binding into the sourcecode and not writing it into the Interface Builder?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about interface-builder