Can you see the values of NSUserDefaults naywhere in the xcode debugger?
Just wondering if this is possible?
Thanks,
Nick
All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId.
Storing Data in User Defaults The user's defaults database is stored on disk as a property list or plist. A property list or plist is an XML file. At runtime, the UserDefaults class keeps the contents of the property list in memory to improve performance.
When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.
Overview. The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.
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)
I don't have a solution to view them in the debugger, but I can offer this:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"%@", [defaults dictionaryRepresentation]);
For some caveman-debugging:)
EDIT: As David suggest in the comment, we can now do this in the debugging console:
po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
Swift 3.0
po UserDefaults.standard.dictionaryRepresentation()
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