如何在 iPhone 模拟器中重置 NSUserDefaults 数据?

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

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

问题描述

我已将 NSUserDefaults 数据检索添加到我的应用程序中,这非常好.但为了测试,我想重置我添加到默认数据库的所有数据,以便用户第一次启动应用程序时一切都处于状态.

I've added NSUserDefaults 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];

但这并没有做任何事情.默认值仍会保存并可以检索.

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

推荐答案

最简单的方法是从模拟器中删除应用程序 - 就像您从真实手机中删除它一样,通过点击(单击)并按住直到图标开始振动.这会删除所有应用数据,下次您从 Xcode 安装时就像第一次一样.

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 的目录.在该目录中,在 Library/Preferences 中查找首选项文件.删除它,用户偏好就消失了.

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 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 iPhone 模拟器中重置 NSUserDefaults 数据?

基础教程推荐