ios 是否有比删除其目录更快/更好的方法来清除 iPhone 模拟器缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8323819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:41:19  来源:igfitidea点击:

Is there a quicker / better way to clear the iPhone Simulator cache than deleting its directory?

iosiphonexcodeios-simulator

提问by Luke

So I'm still reasonably new to iOS development and I'm finding myself quite regularly needing to delete either DerivedData, or the contents of the iPhone Simulator directory, to get things to actually execute from my code. Clean in Xcode doesn't do the same as emptying those directories, right? And if not, is there an easier way to do it than lugging Finder around to get to them, and clearing them?

所以我对 iOS 开发还是相当陌生,我发现自己经常需要删除 DerivedData 或 iPhone Simulator 目录的内容,以便从我的代码中实际执行一些事情。Xcode 中的 Clean 与清空这些目录的作用不同,对吗?如果没有,是否有比拖着 Finder 四处寻找并清除它们更简单的方法呢?

回答by SwiftArchitect

66:99 and climbing:

66:99 和攀登:

Yes, there is a better way than going into every single simulator in town, and resetting contents and settings one at a time. Also much betterthan looking into your simulator's directory and yanking the cache from under its feet.

是的,有比进入镇上的每个模拟器并一次重置一个内容和设置更好的方法。也比查看模拟器的目录并从其脚下拉动缓存要好得多

Quit iPhone Simulator, then run xcrunin Terminal:

退出 iPhone 模拟器,然后xcrun在终端中运行:

xcrun simctl erase all

Safe and effective.

安全有效。

See https://stackoverflow.com/a/26394597/218152for single device

单个设备见https://stackoverflow.com/a/26394597/218152

xcrun simctl erase [device ID]

xcrun simctl 擦除 [设备 ID]

回答by Jeff Wolski

In the iOS Simulatormenu, there is an option called Reset Content and Settings...

iOS Simulator菜单中,有一个选项叫做Reset Content and Settings...

This should do the trick.

这应该可以解决问题。

EDIT:

编辑:

To make this much quicker and easier, I added a shortcut key like this...

为了使这更快更容易,我添加了一个这样的快捷键......

In System Preferences, choose Keyboard

在系统偏好设置中,选择键盘

Keyboard System Preferences

键盘系统偏好设置

Then choose the Shortcutstab. And click App Shortcuts

然后选择快捷方式选项卡。然后单击应用程序快捷方式

App ShortcutsClick the plus button to add another shortcut.

应用快捷方式单击加号按钮添加另一个快捷方式。

enter image description hereLastly:

在此处输入图片说明最后:

  1. Click theChoose Simulatorfrom the Application:drop-down. If it's not there, scroll to the bottom of the application list and choose "Other...". Then type "simulator" into the search and add the Simulator from there.
  2. Type Erase All Content and Settings...into the Menu Title:text-box.
  3. Type your preferred shortcut key into the Keyboard Shortcut:. (I use command-period)
  4. Click the Addbutton.
  1. 点击theChoose模拟器应用程序:下拉。如果它不在那里,滚动到应用程序列表的底部并选择“其他...”。然后在搜索中输入“模拟器”并从那里添加模拟器。
  2. 菜单标题:文本框中键入擦除所有内容和设置...。
  3. 键盘快捷键中键入您喜欢的快捷键。(我使用命令句点)
  4. 单击添加按钮。

enter image description here

在此处输入图片说明

Now, while in your iOS Simulator, you can simply use your new shortcut key to reset.

现在,在您的 iOS 模拟器中,您只需使用新的快捷键即可进行重置。



If the Simulator doesn't appear in the drop down list:

如果模拟器没有出现在下拉列表中:

  1. In a Finder window, go to your Applications folder.
  2. Right-click Xcode and choose "Show Package Contents".
  3. Navigate to Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/
  4. You will see iPhone Simulator.app.
  5. Now, in the Settings app, instead of choosing iOS Simulator which is missing, you choose Other....
  6. This will cause a window to appear that has a list of Applications.
  7. Now, drag iPhone Simulator.app from your Finder window to the window that appeared when you clicked Other....
  1. 在 Finder 窗口中,转到您的应用程序文件夹。
  2. 右键单击 Xcode 并选择“显示包内容”。
  3. 导航 Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/
  4. 您将看到 iPhone Simulator.app。
  5. 现在,在“设置”应用程序中,您不再选择缺少的 iOS 模拟器,而是选择其他...。
  6. 这将导致出现一个包含应用程序列表的窗口。
  7. 现在,将 iPhone Simulator.app 从 Finder 窗口拖到单击其他...时出现的窗口。

回答by Adrian Florescu

For webdevelopment and testing on the iOS Simulator (Safari):

对于iOS 模拟器 (Safari) 上的Web开发和测试:

  1. With both iOS Simulator and Safari open, go to Safari > Develop > iOS Simulator and select your page which will give you access to the Web Inspector tools.

  2. Go to Safari > Develop > Empty Caches to clear the cache on iOS Safari.

  1. 在 iOS Simulator 和 Safari 都打开的情况下,转到 Safari > Develop > iOS Simulator 并选择您的页面,这将使您可以访问 Web Inspector 工具。

  2. 转到 Safari > 开发 > 清空缓存以清除 iOS Safari 上的缓存。