21

Is there any option to reset the contents and settings of all the simulators ?In a single event or a single command via command line?

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101

14 Answers14

40

Based on the the answer from Jeremy Huddleston Sequoia I wrote a shell script that will reset all simulators.

For Xcode 7 you can use:

#!/bin/sh

instruments -s devices \
| grep "(\d[.0-9]\+) \[[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}\]" \
| grep -o "[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}" \
| while read -r line ; do
    echo "Reseting Simulator with UDID: $line"
    xcrun simctl erase $line
done

For previous versions use:

#!/bin/sh

instruments -s devices \
 | grep Simulator \
 | grep -o "[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}" \
 | while read -r line ; do
    echo "Reseting Simulator with UDID: $line"
    xcrun simctl erase $line
done
Daniel Wood
  • 4,487
  • 3
  • 38
  • 36
  • You forgot a `"` Character at the end of your regex. Can't edit for one character, so I'm just commenting :) – Rémy Virin Oct 23 '14 at 08:14
  • Hi Daniel. This worked flawlessly, but it stopped working for xcode7. I think you need to change the regex – eertl Sep 18 '15 at 11:57
29

With Xcode 6, you can use the simctl command line utility:

xcrun simctl erase <device UDID>

With Xcode 7, you can erase all at once with:

xcrun simctl erase all
Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • 1
    To anyone reading these answers, I will say that this is definitely a better option than simply whacking the application support iPhone Simulator folder with rm -rf. – Mark Edington Jun 14 '15 at 19:23
12

With Xcode 10:

#!/usr/bin/env sh

xcrun simctl shutdown all
xcrun simctl erase all
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
10

I present,

The Definitive iOS Simulator Reset Script (link)

enter image description here

Based on Oded Regev's code from this SO question (which was based on Jacob Rus's fine "menu_click" code)

Community
  • 1
  • 1
Stian Høiland
  • 3,625
  • 2
  • 27
  • 32
5

Inspired by the answer from Daniel Wood, I came up with this one.

It solves the problem of what to do with a running simulator. Our CI environment leaves the simulator running after the tests run, and that's getting more tainted over time.

The guid detection isn't as accurate, but I think the readability trade-off is worthwhile.

#!/bin/bash
xcrun simctl list | grep Booted | grep -e "[0-9A-F\-]\{36\}" -o | xargs xcrun simctl shutdown
xcrun simctl erase all

Tested with the XCode 7.

Dan Caseley
  • 521
  • 6
  • 8
5

With the latest version of Xcode command line tools you can call xcrun simctl erase all

Make sure to quit the sim every time you call this function or you'll get an error stating An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=159): Unable to erase contents and settings in current state: Booted

Laser Hawk
  • 1,988
  • 2
  • 23
  • 29
5

you can run this command xcrun simctl erase all

IgnazioC
  • 4,554
  • 4
  • 33
  • 46
3

Simply go to ~/Library/Application Support/iPhone Simulator and delete all the contents out of there. The above methods don't work on iOS 7, so this seemed to work for me.

Zoyt
  • 4,809
  • 6
  • 33
  • 45
2
xcrun simctl erase all
xcrun simctl delete unavailable
Hogdotmac
  • 282
  • 6
  • 7
1

I wrote a script that will reset the contents & settings of all versions and devices for the iOS Simulator. It grabs the device names and version numbers from the menu, so it will include any new devices or iOS versions that Apple releases simulators for.

It's easy to run manually or use in a build-script. I would suggest adding it as a Pre-Action Run Script before the build.

It's based heavily on Stian's script above, but doesn't become stale with new iOS versions, and eliminates the dialog box (better for automation build scripts).

https://github.com/michaelpatzer/ResetAllSimulators

M-P
  • 4,909
  • 3
  • 25
  • 31
1

1) Quit from all simulators

2) Run below command in terminal xcrun simctl erase all

0

There is a tool xctool - https://github.com/facebook/xctool which is replacement of xcodebuild. It allows to build application from command line as well as run tests for it. Besides running tests it is allows to provide arguments such as -freshSimulator and -freshInstall that resetting content for target simulator before executing tests. That simplifies a lot resetting of simulator, as you avoiding various magic with bash scripts etc everything encapsulated within tool.

Nikita Leonov
  • 5,684
  • 31
  • 37
-1

To set the user content and settings of the simulator to their factory state and remove the applications you have installed, choose iPhone Simulator > Reset Content and Settings.

memmons
  • 40,222
  • 21
  • 149
  • 183
  • 1
    this only resets one. he didnt ask that :) he asked to reset multiple at once! – Daij-Djan Mar 13 '13 at 08:44
  • So he cannot do it directly. one could write a bash schript / apple script to directly modify the filesystem.... all the sims are under ~/Library/Application Support/iPhone Simulator/%VERSION% – Daij-Djan Mar 13 '13 at 08:45
-1

You can call this command:

rm -rf ~/Library/Application Support/iPhone Simulator
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
Aist Marabu
  • 169
  • 2
  • 9