Data binding / NSArrayController: What is the job of the Object Controller

642 views Asked by At

Every tutorial I read about data binding / NSArrayController told to set the Mode and the Keys in the Object Controller (Attributes Inspector) for the data model class I use. Why do I have to do this?

In my sample application I create all objects in code and add them to the array controller in code too. The program still works fine without any settings in the Object Controller. I use the NSCollectionView to present my data.

enter image description here

1

There are 1 answers

0
Swift Dev Journal On

To answer the question in the subject, the Object Controller section lets you determine what the array controller is controlling. In your screenshot the array controller is controlling objects of a Person class. But the array controller can also control a Core Data entity. That's what the Mode menu is for. The keys are pieces of the object/entity the array controller is controlling.

The reason the tutorials tell you to set the mode and keys is they are demonstrating using NSArrayController with Cocoa bindings. You must set the mode and keys so you can bind the array controller to the collection view in Interface Builder and have the collection view display relevant data from the array controller. If you are writing code to do all the NSArrayController work and not using Cocoa bindings, you can avoid setting the mode and keys.