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


当前回答

它将在更高版本的SWIFT 4上工作

只需要把代码放在AppDelegate的any方法中,并在那里设置断点

**> let path =
> NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory,
> FileManager.SearchPathDomainMask.userDomainMask, true).first**

当你运行一个项目,打印“路径”,你会得到路径到达信息。使用userdefaults进行Plist 然后到finder,粘贴这个路径 那份文件找到你了

其他回答

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

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

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

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

对于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;
    ...

斯威夫特3

print(UserDefaults.standard.dictionaryRepresentation())

您可以检查数组中由返回的每个键的值

[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]