Binding two dimensional array to a tableview

Hi! Is it possible to bind a two dimensional array like this

property myArray : {{"A -> B","aaa","bbb"},{"A -> C","aaa","ccc"}}

to a table view with 3 columns?

I suspect you’ll need an array of records/dictionaries.

. and preferably an NSArray of NSDictionaries. :wink:

Unless you want it editable, in which case you’d want an NSMutableArray of NSMutableDictionaries. Which is what a list of records will be treated as.


Be extremely careful about these points, as you will mix two different structures through the ASOC bridge :

  1. type coercion : never assume an object you pass to Cocoa will return identical (strings or numbers);
  2. what is editable and what is not : as Shane said, everything you want to edit must be a mutable object;
  3. typing : try one binding at a time, because you will spend time to find what went wrong in IB (unless you app crashes at launch, giving the mistyped key name – but you must know that);
  4. KVO - compliance : a property declared in the script and bound in IB can be observed by the variable updating system of Cocoa. I’m not sure the keys of an AS record can be.

Note for Shane,

Ric and me have spend a lot of time to solve these problems, especially with NSTableView bindings: an AS record declared as property and whose keys were bound in IB raised a non-KVO compliance error, because ASOC bridges AS record to a Cocoa NSDictionary, which is non-mutable. I had to initialize a NSMutableDictionary, using the AS record, to make things work in the interface.


I’m not sure what you mean – the example in chapter 6 of my book use a list of records. But you may have problems if you don’t use an array controller, and when you make changes, the records get changed to mutable dictionaries anyway.


We did use an array controller. I had my AS record declared as property, bound via an array controller, and when this record was changed (by file operations) I got an error saying the record had been changed without sending the appropriate notification (to the key value notification center).

I tried to put “MY” before the references, but it didn’t work.

Maybe there was an error elsewhere, but as soon I replaced the record by a mutable dictionary, everything suddenly worked like magic.

Anyway, I learned that it’s always better to do things the more Cocoa-manner as possible when bindings are involved.