Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 503
nickthedude Avatar asked Jun 14 '10 18:06

nickthedude


People also ask

Where are the NSUserDefaults values stored?

All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId.

Where are UserDefaults stored?

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.

How do I show debugger in Xcode?

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.

What is NSUserDefaults in Swift?

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.


2 Answers

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)
like image 50
Justin Bush Avatar answered Oct 21 '22 09:10

Justin Bush


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()
like image 44
RickiG Avatar answered Oct 21 '22 09:10

RickiG