iPhone SDK Tips & Tricks
Save data:
NSString *testValue = [[NSUserDefaults standartUserDefaults] stringForKey:@”stringKey”];
if(testValue == nil)
{
//set default value
[[NSUserDefaults standartUserDefaults] setInteger:42 forKey:@”intKey”];
[[NSUserDefaults standartUserDefaults] setObject:@”data” forKey:@”stringKey”];
[[NSUserDefaults standartUserDefaults] setDouble:3.1415 forKey:@”doubleKey”];
[[NSUserDefaults standartUserDefaults] setFloat:1.23 forKey:@”floatKey”];
[[NSUserDefaults standartUserDefaults] synchronize];
}
Read data:
NSString *defaultString = [[NSUserDefaults standartUserDefaults] stringForKey:@”stringKey”];
int defaultInt = [[NSUserDefaults standartUserDefaults] integerForKey:@”intKey”];
//or NSInteger *defaultInt
int defaultFloat = [[NSUserDefaults standartUserDefaults] floatForKey:@”floatKey”];