Objective C - Keeping NSInteger Value after app quite

Discussion in 'Mac Programming' started by Narcs, Jan 26, 2012.

  1. Narcs macrumors newbie

    Jan 19, 2012
    I have an NSInteger in the appDelegate called saveInt. As the user changes through views the saveInt will change. So it starts as zero, then the person goes to another view and saveInt will change to 1.
    Now what I want to do is be able to quit the app, as in not run it in the background but completely quit the application. Then when i re-open the application, I want saveInt to still be equal to 1.
    How would I do this? If you need to see any code just ask.
  2. jared_kipe macrumors 68030


    Dec 8, 2003
    Well the simplest would be to write it to a file every time it changes, or on exit.

    A class is already around to facilitate this by saving it to ~/Library/Preferences for you.

    NSUserDefaults class, check it out.

Share This Page