96

I just finished writing some code that checks if it is the first time the app is running then display a message, if it is not the first time then display another message..

How do you reset the simulator on Xcode so that I can test the app when it runs the first time?

I tried cleaning the build folder but it didn't work..

Tim
  • 8,932
  • 4
  • 43
  • 64
user2301717
  • 1,049
  • 1
  • 10
  • 13

6 Answers6

152

In the iOS Simulator, press iOS Simulator in the menu at the top of the screen, and press 'Reset Content and Settings...'. This will clear the entire simulator.

Or, on the home screen of the simulator, uninstall the app in the same way you would on a physical device, by pressing and holding on the application icon until an 'x' appears in the top left, and press the 'x', and select 'Delete' from the alert view. This will clear all data associated with a single app.

Then do a clean, build and run.

Edit:

As of Xcode 11+ Simulator, this is under Device > Erase All Content and Settings

Tim
  • 8,932
  • 4
  • 43
  • 64
  • 11
    "Reset content and settings" should be as a last resort. It wipes the entire simulator, causing its copy of iOS to take a long way to start up. And it wipes all the database, including any images you may have added to its photo library, etc. Deleting the app is much faster and only wipe's the app's content. – David C. Jan 05 '18 at 19:59
  • 4
    It depends on what type of data you're trying to erase. For example, if you're trying to remove 3rd-party login credentials that the app is relying on, then deleting just the app wouldn't suffice. However if that's not the case, then removing the app as @DavidC. suggested works perfectly. – craft Aug 14 '18 at 00:54
  • 6
    **Update:** Changed to **Hardware > Erase All Content and Settings...** – Gal Bracha Nov 24 '18 at 20:27
  • 8
    Update: Changed to Device > Erase All Content and Settings – Paolo Aug 18 '20 at 07:05
45

The correct way to do this in XCode is: (Simulator must be shut down first)

xcrun simctl erase <device UDID> or xcrun simctl erase all

To find out the UDID use:

xcrun simctl list

Jose Llausas
  • 3,366
  • 1
  • 20
  • 24
  • 1
    Note, the simulator must be shutdown for this to work. Meaning the Simulator>Reset Contents and Settings... option kind of makes this command redundant – Daniel Wilson Mar 02 '17 at 11:50
25

Currently (Simulator Version 10.0), you can do it the following way:

Hardware > Erase All Content and Settings...

The screenshot of the way to reset Simulator

Darius Miliauskas
  • 3,391
  • 4
  • 35
  • 53
4

@Tim's answer is probably easier for interactive usage.

We use scripts for automated testing and delete the simulator's data directory to ensure it's clean. The simulator will re-create basic information when it restarts.

Delete the following:

~/Library/Application Support/iPhone Simulator/${simulator.version}

3

All of the answers are how to delete an app, or how to erase all simulator content and settings. If you want to delete just content and settings for specific simulator app find the following folder and delete it:

~/Library/Developer/CoreSimulator/Devices/{DEVICE_UDID}/data/Containers/Data/Application/{APP_UDID}

Where {DEVICE_UDID} is identifier for specific simulator and {APP_UDID} is identifier for specific app.

Mirko
  • 2,231
  • 2
  • 21
  • 17
2

Don't really know if this is the best way but following is working for me:

first kill all working Simulators with

killall Simulator 2>&- && sleep 5 || true

afterwards reset all devices with

xcrun simctl erase all

ps.: I'm working with XCode 8

Sandu
  • 480
  • 5
  • 13