Byron
Byron

Reputation: 293

iOS data access throughout an app

I am looking into the most efficient and secure way of handling data in an iOS app.

I have used singletons, yet after reading a number of articles I have come to the conclusion this is not the best way to handle data, the singleton data is essentially global variables.

My apps data is stored in a plist, with a controller(DataManager) handling the conversion from plist file to variables stored within the DataManager class.

What other options are there to making this data available to my View Controller, subsequent scenes (I'm using SKSpriteKit) and the app delegate? As apposed to making DataManager a singleton or creating multiple instances of DataManager all over the program.

I have thought about passing data between scenes when pushing and pulling, but would this be causing a high level of coupling?

Regards Byron

Upvotes: 3

Views: 125

Answers (1)

Dumoko
Dumoko

Reputation: 2644

  • Sending data back and forth between the ViewControllers - that is a concept that can be said that is definitely wrong. - it is not MVC

  • Since the data that needs to be accessed doesn't seem to be huge (like huge arrays, a lot of text, or any data that would be nice to keep in a Database), a Singleton pattern does seem like a good idea.

  • NSUserDefaults - it is initially good for storing only settings, or some static data, like username, tokens, and if it is important to keep the data even after the App is killed.

  • The data should be stored in data models, and the access to these models should be handled by special classes, that are usually using singleton pattern.

So using the class might look like

[ProgressManager sharedInstance].level = level;

This was you will adhere to MVC pattern which is the key one. VC should access models, take the data from them, and tell the views what exactly to show.

Don't know what you use the timer for - but if it's for some global purposes (not just time since last jump of the character), it would be nice to have a separate class that would handle these global timer firings.

Otherwise the timer would be good to keep encapsulated in the space that is working with it.

Upvotes: 1

Related Questions