有没有办法直接看到什么被保存到NSUserDefaults ?我想看看我的数据保存是否正确。
当前回答
你可以NSLog你设置的每个值,比如:
NSLog(@"%@",[[NSUserDefaults standardDefaults] stringForKey:@"WhateverTheKeyYouSet"]);
其他回答
你可以NSLog你设置的每个值,比如:
NSLog(@"%@",[[NSUserDefaults standardDefaults] stringForKey:@"WhateverTheKeyYouSet"]);
在Swift 4.0中
//func dictionaryRepresentation() -> [String : AnyObject]
因为NSUserDefaults.standardUserDefaults()返回[String: AnyObject]
我们将它转换到NSDictionary中。然后用括号'()'把它括起来将允许我们调用。allkeys或。allvalues就像你在任何NSDictionary上一样
print((UserDefaults.standard.dictionaryRepresentation() as NSDictionary).allKeys)
对于希望找到存储在模拟器中的首选项的新位置的用户。 这是我找到存储值的地方。
/Users/vikas/Library/Developer/CoreSimulator/Devices/CE5A0444-BD98-4FEE-A839-92728D6E9895/data/Containers/Data/Application/F7430839-ED2C-408A-8A8E-FE7FFAABA8E2/Library/Preferences
因为我们可以看到有很大的标识符,很难从终端猜出来,所以我建议在终端或finder中搜索它们。
文件名应该以{bundle id}结尾。Plist,例如com.sellerbuddy.online.plist,这样你就可以直接进入终端,输入你的应用程序包标识符。
find ~/Library/Developer/CoreSimulator/Devices -type f -name "com.sellerbuddy.online.plist"
您可以检查数组中由返回的每个键的值
[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]
你可以打印当前所有的NSUserDefaults到日志:
键:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
键和值:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
推荐文章
- 如何删除默认的导航栏空间在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是可动画的吗?