Is there a way to get all values in NSUserDefaults? [duplicate] Is there a way to get all values in NSUserDefaults? [duplicate] ios ios

Is there a way to get all values in NSUserDefaults? [duplicate]


Objective C

all values:

NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allValues]);

all keys:

NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);

all keys and values:

NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);

using for:

NSArray *keys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];for(NSString* key in keys){    // your code here    NSLog(@"value: %@ forKey: %@",[[NSUserDefaults standardUserDefaults] valueForKey:key],key);}

Swift

all values:

print(UserDefaults.standard.dictionaryRepresentation().values)

all keys:

print(UserDefaults.standard.dictionaryRepresentation().keys)

all keys and values:

print(UserDefaults.standard.dictionaryRepresentation())


You can use:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];NSDictionary *defaultAsDic = [defaults dictionaryRepresentation];NSArray *keyArr = [defaultAsDic allKeys];for (NSString *key in keyArr){     NSLog(@"key [%@] => Value [%@]",key,[defaultAsDic valueForKey:key]);}


Print only keys

NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);

Keys and Values

NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);