119

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?

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
Luke
  • 9,512
  • 15
  • 82
  • 146

4 Answers4

176

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]

Community
  • 1
  • 1
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • 1
    Does this erase the simulators themselves, though? So that I’d need to re-add them in Xcode's Devices screen afterward? – Luke Nov 20 '15 at 09:19
  • 2
    Just the content. From the documentation (`xcrun simctl help`), **erase**: *Erase a device's contents and settings.*, not to be confused with **delete**: *Delete a device or all unavailable devices.* – SwiftArchitect Nov 20 '15 at 09:38
  • Awesome. Tempted to switch my correct answer in light of this :) – Luke Nov 20 '15 at 13:59
  • @lukech: Much appreciated. I stumbled into this solution while trying to save memory on my HD, and was looking for a `clean build folder` approach. And props to you for keeping this question active. – SwiftArchitect Nov 24 '15 at 16:56
  • this command takes forever to run, how to select target sim with uuid? – the_prole Jun 01 '18 at 16:32
  • make sure to also run: `xcrun simctl delete unavailable` – themenace Jul 31 '22 at 09:03
  • with I could make this work but instead getting `xcrun: error: unable to find utility "simctl", not a developer tool or in PATH` – Mix Master Mike Sep 17 '22 at 01:41
112

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....
Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
  • The iOS Simulator no longer appears in the Application drop-down. Should I just choose "xCode.app"? I'm on OS 10.8.3 with iOS Simulator 6.0. – potench Apr 04 '13 at 22:49
  • 8
    In a finder window, go to your Applications folder. Option-click Xcode and choose "Show Package Contents". Navigate to the `Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/` folder. You will see `iPhone Simulator.app`. Now, in the Settings app, instead of choosing `iOS Simulator` which is missing, you choose `Other...`. This will cause a window to appear that has a list of Applications. Now, drag `iPhone Simulator.app` from your Finder window to the window that appeared when you clicked `Other...`. – Jeff Wolski Apr 04 '13 at 23:07
  • 1
    I came here looking for something else, but went through your steps just because your answer was so good. thanks! – kodybrown Aug 29 '14 at 00:54
  • 1
    `Reset Content and Settings` will not clear client-side assets on a VPN. I was struggling this for a while wondering why my CSS animations worked everywhere except the simulator, only to find out that it was caching old files even when I had deleted content and settings. The only thing that ended up working for me was disconnecting from my VPN and restarting my VM then reconnecting (the framework I use versions all my assets for me) -- you can also version them manually if just testing stuff, but that's annoying. This is something Apple should fix; it only happens when testing for iOS for me. – Benny Schmidt Oct 15 '14 at 18:32
  • 3
    If you can't find the simulator at the path `Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/` as pointed out by @JeffWolski, You can search for it by the search term `simulator.app` – atulkhatri Aug 24 '15 at 05:38
  • I had to do `Reset Content and Settings...` (with the periods) – Steven Kaspar Aug 16 '17 at 18:39
  • In Simulator version 10.0 `Erase All Content and Settings...` worked for me – Will Oct 17 '17 at 14:59
  • Since this was so old, there have been a lot of changes in the OS and IDE. So, I've updated the screenshots and directions, including the those mentioned in the comments. – Jeff Wolski May 07 '19 at 19:08
9

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.

RPL
  • 3,500
  • 2
  • 21
  • 28
Adrian Florescu
  • 4,454
  • 8
  • 50
  • 74
  • @AdrianFlorescu this is a solution for debugging web development on iOS Safari, but I think the question was pertaining to iOS app development. – RPL Jan 06 '16 at 06:04
  • 5
    Does not work on Safari 9.0.3 with remote debugger. "Disable caches" has no effect either. – Gamadril Mar 16 '16 at 08:22
  • 1
    This setting does nothing for me (does not actually clear cache on mobile safari) – HandiworkNYC.com Apr 04 '16 at 17:01
  • Yeah. Looks like it doesn't clean the iOS cache anymore. I guess it did in the past... – Yosh Apr 13 '16 at 15:58
  • 1
    this is the only solution that seems to be working https://stackoverflow.com/a/51421939/1055015 – Exlord Apr 13 '19 at 09:01
5

Web inspector new has option to disable cache 2020 solution

enter image description here

user956584
  • 5,316
  • 3
  • 40
  • 50