Saving
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
// set value
[userDefaults setBool:YES forKey:@"keyForBOOL"];
[userDefaults setDouble:10.5454 forKey:@"keyForDouble"];
[userDefaults setFloat:10.5 forKey:@"keyForFloat"];
[userDefaults setInteger:10 forKey:@"keyForInteger"];
[userDefaults setURL:[NSURL URLWithString:@"http://nsuserdefaults-in-iphone-sdk.blogspot.in/"]forKey:@"keyForURL"];
[userDefaults setObject:@"Hello" forKey:@"keyForObject"];
// saving to user default
[userDefaults synchronize];
Retrieving
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
// get value from user default
BOOL isYou = [userDefaults boolForKey:@"keyForBOOL"];
double varDouble = [userDefaults doubleForKey:@"keyForDouble"];
float varFloat = [userDefaults floatForKey:@"keyForFloat"];
NSInteger varInt = [userDefaults integerForKey:@"keyForInteger"];
NSURL *url = [userDefaults URLForKey:@"keyForURL"];
NSString *str = [userDefaults objectForKey:@"keyForObject"];
No comments:
Post a Comment