From 2d614fa5944835c28c1e36767d2b1f2c3c04d448 Mon Sep 17 00:00:00 2001
From: Matt Oakes <hello@mattoakes.net>
Date: Tue, 21 Apr 2020 16:28:15 +0100
Subject: [PATCH] feat(ios): Ensure a simulator with the latest iOS version
 exists for the given name when testing

---
 src/commands/ios_simulator_start.yml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/commands/ios_simulator_start.yml b/src/commands/ios_simulator_start.yml
index ba183e5..061284e 100644
--- a/src/commands/ios_simulator_start.yml
+++ b/src/commands/ios_simulator_start.yml
@@ -1,4 +1,4 @@
-description: Starts an iOS simulator with the given name.
+description: Creates and starts an iOS simulator with the given name.
 
 parameters:
   device:
@@ -7,6 +7,12 @@ parameters:
     default: "iPhone X"
 
 steps:
+  - run:
+      name: Remove all simulators to avoid conflicts with the one we're going to use
+      command: xcrun simctl list | awk -F “[()]” ‘{ for (i=2; i<NF; i+=2) print $i }’ | grep ‘^[-A-Z0–9]*$’ | xargs -I uuid xcrun simctl delete uuid
+  - run:
+      name: Create the device simulator we need
+      command: xcrun simctl create "<<parameters.device>>" "<<parameters.device>>"
   - run:
       name: Start iOS simulator (background)
       background: true