What's the best way to store global data?

Discussion in 'iOS Programming' started by mistergreen2011, Apr 14, 2011.

  1. mistergreen2011 macrumors member

    Mar 23, 2011
    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?

  2. Animalk macrumors 6502

    May 27, 2007
    Montreal Canada
    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.
  3. dantastic macrumors 6502a


    Jan 21, 2011
    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.
  4. mistergreen2011 thread starter macrumors member

    Mar 23, 2011
    Thanks for the advice. Got it working like you said.

Share This Page