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

所以我对于 iOS 开发还是比较新的,我发现自己经常需要删除衍生数据,或者 iPhone 模拟器目录的内容,以便从我的代码中实际执行一些东西。在 Xcode 清理并不等于清空那些目录,对吗?如果没有,还有比拖着 Finder 到处找他们,然后清理他们更简单的方法吗?

75111 次浏览

In the iOS Simulator menu, there is an option called 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 Shortcuts tab. And click App Shortcuts

App Shortcuts Click the plus button to add another shortcut.

enter image description here Lastly:

  1. Click theChoose Simulator from 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 Add button.

enter image description here

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


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....

For web development and testing on the iOS Simulator (Safari):

  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.

66:99 and climbing:

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 better than looking into your simulator's directory and yanking the cache from under its feet.

Quit iPhone Simulator, then run xcrun in Terminal:

xcrun simctl erase all

Safe and effective.

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

xcrun simctl erase [device ID]

Web inspector new has option to disable cache 2020 solution

enter image description here