'Can you see the values of NSUserDefaults anywhere in the xcode debugger?

Can you see the values of NSUserDefaults naywhere in the xcode debugger?

Just wondering if this is possible?

Thanks,

Nick



Solution 1:[1]

I haven't done it but you should be able to execute a po (print object) command on the user defaults like so:

po [[NSUserDefaults standardUserDefaults] valueForKey:@"someKeyName"] 

I prefer to wrap my defaults in a custom class and create a description method that dumps the defaults.

You can use the "defaults" command line utility to examine the defaults exactly. Read the man page for details.

Solution 2:[2]

Not aware of any GUI that displays NSUserDefaults, but I use this in my application delegate to see the settings at start up:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSLog(@"%@ DEFAULTS = %@", [self class], [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]);
} 

Solution 3:[3]

You can log or either use PO command at debugger for Keys :

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

or for Keys and values:

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

& on debugger use: getting all keys :

 po [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]

for key & values :

po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]

Solution 4:[4]

Updated for Swift 5

Print all UserDefault key-value pairs to console:

print(UserDefaults.standard.dictionaryRepresentation())

Print UserDefault keys to console:

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

Print UserDefault values to console:

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

Solution 5:[5]

read:

po UserDefaults.standard.value(forKey: "key")

write:

po UserDefaults.standard.set(true, forKey: "key")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TechZen
Solution 2 typeoneerror
Solution 3 Ash
Solution 4 Justin Bush
Solution 5 smileBot