Search code examples
objective-ccocoamodelnsarraycontroller

How expensive is it to retrieve a model object from an nsarraycontroller?


I've a window with a table. The table lists several model objects by name. Those model objects back a window and that window's components all depend on the model objects for their values.

Some tables on that window cannot be bound to the model object and must be populated using a data source. In this situation I retrieve the currently selected object from the array controller (selected because the user clicked on the table that lists the model objects) and manipulate them manually.

My question is: how expensive is it to retrieve the model object from the array each time I need it? Should I create a global variable of the type model object and set it every time the user clicks on that table or is it ok to retrieve a value from the array controller every time I need it?


Solution

  • Since all objects in Cocoa are passed around using pointers, there will be very little overhead involved in retrieving your model object from an NSArrayController. Even if you were to use bindings, the same sort of accesses are going on behind the scenes.