PDA

View Full Version : What's the best way to store global data?




mistergreen2011
Apr 14, 2011, 09:54 AM
Hi folks,

I have an app that need a fairly complicate key array/nsdictionary list that it uses to calculate other information. The data isn't large and it needs to be accessible from several classes.

I've been reading around and people have used several methods, a singleton class , EXTERN variables, and property list.

I think apple recommends using plist?

And I would write code to populate the plist with the array. Where do I put this code, in the application didFinishedLaunching? So the xml/plist gets written or rewritten every time the application is launched?

thanks.



Animalk
Apr 14, 2011, 10:27 AM
My immediate gut-instinct would be to create a singleton class at the Application level with class methods for using and accessing its features.

Since it's a singleton class I would try to implement lazy loading. It would only load the data upon first call or after having dumped the data due to a memory warning.

dantastic
Apr 14, 2011, 11:18 AM
I think we are talking about two different things here. If we are talking about persisting a small bit of data then a plist is likely the answer. When it comes to accessing the same data from several classes then singleton is the answer. So in your case you probably want to load data from a plist into a singleton.

mistergreen2011
Apr 16, 2011, 09:46 PM
Thanks for the advice. Got it working like you said.