PDA

View Full Version : Basic Cocoa MVC query - how to keep the same model object around




simongoldring
Apr 3, 2011, 04:17 PM
Hi - I'm just beginning to learn Cocoa, and would appreciate some help with what I believe should be a simple problem.

I've followed and understood most of Apple's currency converter example, and am trying to build on that tutorial's foundations by creating a small Cocoa calculator using the Model-View-Controller (MVC) pattern. In the currency converter example, a new model object is initialized every time a conversion needs to be calculated. However, in my program I would like for the model to be a singleton type object which is kept around after a calculation is performed.

The controller object already behaves like this, as it's added as an object in Interface Builder. Would it be appropriate for me to drag in my model object in a similar way? Or should I do something like override the init method of my controller to allocate the model object then?

Thanks for your help in clearing up my (clearly limited!) understanding in advance,
Simon