有没有办法直接看到什么被保存到NSUserDefaults ?我想看看我的数据保存是否正确。
当前回答
对于 Xcode 7
NSUserDefaults standardDefaults存储在这里:
用户/用户/{}/图书馆/开发/ CoreSimulator /设备/ {UUID} /数据/集装箱/数据/应用程序/ {UUID}
一个套件/应用程序组的NSUserDefaults存储在这里:
/用户/ {USER} /图书馆/开发/ CoreSimulator /设备/ {UUID} /数据/集装箱/共享/ AppGroup / {UUID} / {GROUP_NAME} .plist /图书馆/偏好
我建议使用https://github.com/scinfu/NCSimulatorPlugin,因为现在所有东西都隐藏在uuid后面,很难找到。它允许轻松访问您的模拟器应用程序目录。
其他回答
在Swift 4.0中
//func dictionaryRepresentation() -> [String : AnyObject]
因为NSUserDefaults.standardUserDefaults()返回[String: AnyObject]
我们将它转换到NSDictionary中。然后用括号'()'把它括起来将允许我们调用。allkeys或。allvalues就像你在任何NSDictionary上一样
print((UserDefaults.standard.dictionaryRepresentation() as NSDictionary).allKeys)
您可以使用它来获得用户首选项、缓存和许多其他数据的完整路径
print (NSSearchPathForDirectoriesInDomains(。文件目录。
你可以打印当前所有的NSUserDefaults到日志:
键:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
键和值:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
对于OS X应用程序,使用默认命令行实用程序更简单,而不是寻找应用程序的默认plist文件。
NAME defaults -- access the Mac OS X user defaults system SYNOPSIS defaults [-currentHost | -host hostname] read [domain [key]] defaults [-currentHost | -host hostname] read-type domain key defaults [-currentHost | -host hostname] write domain { 'plist' | key 'value' } defaults [-currentHost | -host hostname] rename domain old_key new_key defaults [-currentHost | -host hostname] delete [domain [key]] defaults [-currentHost | -host hostname] { domains | find word | help } DESCRIPTION defaults allows users to read, write, and delete Mac OS X user defaults from a command-line shell. Mac OS X applications and other programs use the defaults system to record user preferences and other information that must be maintained when the applications aren't running (such as default font for new documents, or the position of an Info panel). Much of this information is accessible through an appli- cation's Preferences panel, but some of it isn't, such as the position of the Info panel. You can access this information with defaults
例子:
$ defaults read com.apple.Safari
{
AutoplayPolicyWhitelistConfigurationUpdateDate = "2018-08-24 17:33:48 +0000";
AutoplayQuirksWhitelistConfigurationUpdateDate = "2018-08-24 17:33:48 +0000";
DefaultBrowserPromptingState2 = 4;
...
我在桌面上保留了模拟器文件夹的快捷方式,在那里保存应用程序,即:
/Users/gary/Library/Application Support/iPhone Simulator/User/Applications
按最近的日期排序,然后进入最近的应用程序文件夹库/首选项,并在plist编辑器中查看文件。
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- Swift:声明一个空字典
- “你有邮件”的消息在终端,os X
- 为什么ARC仍然需要@autoreleasepool ?
- Mac OS X中的环境变量
- 在成功提交我的应用程序后,“太多符号文件”
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 如何从macOS完全卸载蟒蛇
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?