sharing data between views

Discussion in 'iOS Programming' started by blue-lion, Mar 12, 2012.

  1. macrumors member

    Jan 26, 2010
    Hi, can i ask what is the most common (and best) way of sharing data on iPhone apps between views?. Basically I'm designing a simple game where the game play takes place on one tab bar, but the stats for the game may have to be viewed, even edited on say the settings tab and seen on another high score tab. Do you see what i mean?, the same data will be used in multiple places throughout the app?. i've read about 'singletons', and/or perhaps i should be storing the data using some data persistence technique as i move between views and refreshing the views each time. Is this the way its usually done ?
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Data persistence is a concept that can be achieved through a number of solutions, one of which is singletons. Others include NSUserDefaults, saving to .plists, CoreData, etc. Which one to use is not that simple a question, as often multiple solutions can be used to achieve the same result. But, you might want to consider looking deeper into the Model part of the MVC design pattern, so that you have the flexibility of changing the implementation of data persistence without having to change how your controllers interact with it.
  3. thread starter macrumors member

    Jan 26, 2010
    Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3)


Share This Page