PDA

View Full Version : Objective C - Keeping NSInteger Value after app quite




Narcs
Jan 26, 2012, 10:39 AM
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.



jared_kipe
Jan 26, 2012, 10:49 AM
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.