NSUserDefaults Save, Get, Clear...
// to store in user defaults
NSUserDefaults *StoringKeys = [NSUserDefaults standardUserDefaults];
[StoringKeys setValue: whatever you want to store forKey:@"key1"];
[StoringKeys setValue:whatever you want to store forKey:@"key2"];
[StoringKeys setValue:whatever you want to store forKey:@"key3"];
[StoringKeys synchronize];
// to get wherever you want those keys
NSUserDefaults * StoringKeys = [NSUserDefaults standardUserDefaults];
NSString * key1 = [StoringKeys valueForKey:@"key1"];
NSString * key1 = [StoringKeys valueForKey:@"key2"];
NSString * key1 = [StoringKeys valueForKey:@"key3"];
DLog(@"key1: ======> %@", key1);
// To clear or reset all the userDefaults
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
// To clear specific key value in userDefaults
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MyKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
No comments:
Post a Comment