如何在iPhone模拟器中重置NSUserDefaults数据? [英] How can I reset the NSUserDefaults data in the iPhone simulator?

查看:140
本文介绍了如何在iPhone模拟器中重置NSUserDefaults数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了NSUserDefault数据检索到我的应用程序,这是相当不错。但是对于测试我想重置所有我添加到默认数据库的数据,所以一切都是在用户第一次启动应用程序的状态。

I've added NSUserDefault data retrieval to my app, which is pretty nice. But for testing I would like to reset all the data I added to the defaults database, so that everything is in the state when the user launches the app the first time.

我试图调用:

[NSUserDefaults resetStandardUserDefaults];

[NSUserDefaults resetStandardUserDefaults];

但是没有做任何事情。

but that doesn't do anything. The defaults are still saved and can be retrieved.

推荐答案

最简单的方法是从模拟器中删除应用程序 - 就像您可以通过点击(点击)并按住,直到图标开始振动,从真实的手机中删除它。

The easiest way is to remove the app from the simulator-- just like you'd remove it from a real phone, by tapping (clicking) and holding until the icons start vibrating. That removes all app data, and the next time you install from Xcode it's like the first time.

如果你有其他应用程序的数据,你需要保持,你有一对夫妇

If you have other app data you need to keep, you have a couple of options.

一种方法是在每个默认键上调用removeObjectForKey:的调试代码。

One way would be to have some debug code that calls removeObjectForKey: on each of your defaults keys.

另一个是找到安装模拟器副本的目录,并删除包含首选项的文件。使用它来查找应用程序:

The other is to find the directory where the simulator copy is installed, and remove the file containing the preferences. Use this to find the app:

ls -ld ~/Library/Application\ Support/iPhone\ Simulator/User/Applications/*/*.app

应用程序的完整路径将包含名称为UUID的目录。在该目录中,查看库/首选项中的首选项文件。删除该用户,用户偏好设置已删除。

The full path to your app will contain directory whose name is a UUID. In that directory, look in Library/Preferences for the preferences file. Remove that, and user preferences are gone.

这篇关于如何在iPhone模拟器中重置NSUserDefaults数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆