Does anyone know of a quick way to dump the standardUserDefaults of NSUserDefaults via NSLog? This is what I have:
NSLog(@"NSUserDefaults dump: %@", [NSUserDefaults standardUserDefaults]);
But it returns:
NSUserDefaults dump: <NSUserDefaults: 0x50b520>
...which is not quite what I'm looking for. I'd really like to have key-value pairs.
Any help or a point in the right direction would be greatly appreciated. Cheers!
NSLog(@"NSUserDefaults dump: %@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
Thanks to Don McCaughey, my business partner and friend, for fixing up my code for me and supply a concise answer. To share it with the rest of you here is a code snippet:
NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];
NSString *bundleId = [bundleInfo objectForKey: @"CFBundleIdentifier"];
NSUserDefaults *appUserDefaults = [[NSUserDefaults alloc] init];
NSLog(@"Start dumping userDefaults for %@", bundleId);
NSLog(@"userDefaults dump: %@", [appUserDefaults persistentDomainForName: bundleId]);
NSLog(@"Finished dumping userDefaults for %@", bundleId);
[appUserDefaults release];
As you can see, everyone who was answering the question was on the right track, but no code offered up was the solution - until Don's editing of our code in source control. Thanks All!
Try:
NSLog(@"NSUserDefaults dump: %@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
dictionaryRepresentation returns an NSDictionary representation of the defaults.
NSLog(@"%@ defaults = %@", [self class],
[[NSUserDefaults standardUserDefaults]
persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With