I am currently creating my first Swift / Mac application and I have the problem of sharing a model (in the MVC sense) between several controllers.
In C# for example one would first create a model, then a number of view models, and then plug that model into them like this:
var gameEngine = new MyGameEngine()
var vm1 = new ViewModelCockpit(gameEngine);
var vm2 = new ViewModelOptionsDialog(gameEngine);
However, in XCode it seems that my controllers I am supposed to place into the .xib
, which are, in turn, automatically instantiated.
What is given Swift's language features and XCode / Objective-C existing standards the best and most professional way have a number of heavyweight models that can be shared and accessed from several controllers? (Heavyweight in the sense that they take some time, memory or complex logic / dependencies) to load and might not easily be put into the .xib
themselves.
Potential answers could be: global variables, some magic / static properties, ... Ideally the solution should feel solid in a software engineering sense and take Swift's language features into account.