i’m working on a little iOS project, and i stumbled across a problem with variable scoping.
what i need is an object that is initialised at launchtime, and is available to all controllers until the application closes.
the object will hold data that is loaded either from a database (sql) or from local storage – im not 100% sure yet what to do here.
i need all viewControllers to access that data-holding object at all times, and i need the object to retain when the app enters the background.
is this possible to achieve? and if, then how would i do it?
for simple variables i know i can use extern variables, but does it also work for complete objects?
thanks for an answer,
sebastian
This is one of the more common questions here. I would advise to stay away from
externvariables and singletons, see my answer for this related question and this sample Xcode project for a better solution. (The sample project is very bare-bones at the moment, I will add more common scenarios later.)