Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save variables after application shut down?

I want to save some integers after application shut down and restore them after application opening, what is the easiest way to do this?

like image 729
vburojevic Avatar asked Jul 12 '11 21:07

vburojevic


1 Answers

You should store and load data from NSUserDefaults:

http://developer.apple.com/library/IOS/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// to store
[defaults setObject:[NSNumber numberWithInt:12345] forKey:@"myKey"];
[defaults synchronize];

// to load
NSNumber *aNumber = [defaults objectForKey:@"myKey"];
NSInteger anInt = [aNumber intValue];
like image 190
Zeppomedio Avatar answered Oct 08 '22 07:10

Zeppomedio