Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jeremy.king

macrumors 603
Original poster
Jul 23, 2002
5,479
1
Holly Springs, NC
I'm curious in getting opinions on the best place to store application data - meaning data that is shared between two or more views. In my case, I only need the model to live as long as the application but I struggle with the best place to manage it and wanted the experienced opinions of others.

My app setup is a tab bar based application with each tab view having its own controller. I thought about using the tab bar controller manage the model and inject into each view controller as needed, but then I have a dependency on the tab bar itself. I also thought about a Singleton data storage object that wouldn't have a dependency and I can access from any class. It also crossed my mind to store it in the Application Delegate, but that just felt dirty to me.

So how do you guys handle the model that needs to be accessed from several views?

Thanks in advance.

P.S. I'm reading the View Controller Programming guide right now.
 

ayasin

macrumors 6502
Jun 26, 2008
318
0
Use a singleton. Basically you create a class that has a class method called something like sharedInstance. This will return the same instance no matter who asks for it. This way you have the same data across all views.
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
I would go the approach of having some kind of singleton model locator object that returns instances of the objects you need; I wouldn't make your actual model objects singletons.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.