Is there a way to see what's been saved to NSUserDefaults
directly? I'd like to see if my data saved correctly.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
I built this method based on Morion's suggestion for better presentation. Use it by calling
[self logAllUserDefaults]
In Swift 4.0
because dictionaryRepresentation of NSUserDefaults.standardUserDefaults() returns [String : AnyObject]
We cast it into an
NSDictionary
. Then by surrounding it in parenthesis '()' will allow us to to call .allKeys or .allValues just as you would on any NSDictionaryI keep a shortcut on my desktop to the simulator's folder where it keeps the apps, ie:
Sorted by most recent date, then just go into the most recent app folder Library/Preferences and view the file in the plist editor.
In Swift we can use the following:-
Swift 3.x & 4.x
For getting all keys & values:
For retrieving the complete dictionary representation of user defaults:
For retrieving the keys:
For retrieving the values:
We can use dump here as well, but that will return the complete inheritance hierarchy of each element in the values array. If more information about the objects is required, then use dump, else go ahead with the normal print statement.
Swift 2.x
For retrieving the complete dictionary representation of user defaults:
For retrieving the keys:
For retrieving the values:
I sometimes use the following snippet to print out the location of my NSUserDefaults file when running in the simulator
It yields the path to the preferences folder
Your NSUserDefaults file is located in the preferences folder and named according to your prefix and appliation name e.g.
I expect the same to be true for the actual device.
Look for the Mac app called SimPholders2. It lives in the menu bar, and lists all of the simulators you've used, and then shows each of your apps. Select one and you get a new Finder window, already open to the app's directory. This makes it super easy to find your app and all of it's directories. It's a huge time saver (and I readily donated to the author).