有没有办法直接看到什么被保存到NSUserDefaults ?我想看看我的数据保存是否正确。


当前回答

MacOS应用 进入:/Users/{User}/Library/Containers/com。{你的公司}。{your app}/Data/Library/Preferences,然后用Xcode打开你的app的pList。

其他回答

我在桌面上保留了模拟器文件夹的快捷方式,在那里保存应用程序,即:

/Users/gary/Library/Application Support/iPhone Simulator/User/Applications

按最近的日期排序,然后进入最近的应用程序文件夹库/首选项,并在plist编辑器中查看文件。

在Swift 4.0中

//func dictionaryRepresentation() -> [String : AnyObject]

因为NSUserDefaults.standardUserDefaults()返回[String: AnyObject]

我们将它转换到NSDictionary中。然后用括号'()'把它括起来将允许我们调用。allkeys或。allvalues就像你在任何NSDictionary上一样

 print((UserDefaults.standard.dictionaryRepresentation() as NSDictionary).allKeys)

你可以NSLog你设置的每个值,比如:

NSLog(@"%@",[[NSUserDefaults standardDefaults] stringForKey:@"WhateverTheKeyYouSet"]);

您可以使用它来获得用户首选项、缓存和许多其他数据的完整路径

print (NSSearchPathForDirectoriesInDomains(。文件目录。

MacOS应用 进入:/Users/{User}/Library/Containers/com。{你的公司}。{your app}/Data/Library/Preferences,然后用Xcode打开你的app的pList。