Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 5, 2009, 02:18 PM   #1
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
Where to store the model?

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.
jeremy.king is offline   0 Reply With Quote
Old Jan 5, 2009, 03:32 PM   #2
ayasin
macrumors 6502
 
Join Date: Jun 2008
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.
__________________
iNeedStuff Shopping Assistant - MacLife called it "the ultimate iPhone grocery list maker".
Follow me on Twitter
Need a developer? PM me.
ayasin is offline   0 Reply With Quote
Old Jan 6, 2009, 02:48 PM   #3
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
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.
Luke Redpath is offline   0 Reply With Quote
Old Jan 6, 2009, 02:49 PM   #4
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
BTW, a great article worth reading if you haven't already is Martin Fowler's of comparison of dependency injection and service locators:

http://martinfowler.com/articles/injection.html
Luke Redpath is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
All iPads: New iPads in refurb store? / Which size/model to get? KUguardgrl13 iPad 2 Jan 24, 2014 04:11 PM
Apple store online tmobile model truelies iPhone 0 Sep 20, 2013 05:07 PM
Anyone with "store" connections? Looking for store model Mac Pros scott911 Mac Pro 2 Jun 21, 2013 05:59 PM
Anyone purchase 2.7ghz model in an Apple store? echo44 MacBook Pro 1 Jun 21, 2012 07:42 AM

Forum Jump

All times are GMT -5. The time now is 11:07 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC