Build once and run multiple Simulators in Xcode or CLI. Tested on Xcode 15.4
Youtube video: https://youtu.be/rEm9NqzoHE0?si=eKRU5rLv8cHNA3i4
a. Copy the script file buildAndRunMultipleSimulators.sh
and paste in on your project root directory.
b. Open the script file and change the following:
-
project name - Go to Xcode -> Settings -> Locations -> Derived Data. Your project name is before the random characters. For example in
SwiftUI-WeatherApp-fyrnhrghniuvzdcfowvoxagsnypn
, your project name isSwiftUI-WeatherApp
. -
app name - Look at your project directory, your app name has extension of
.xcodeproj
-
scheme - At the top of Xcode IDE, left of the simulator name
-
bundle identifier - Go to Targets -> General, under Identity section
c. Edit the buildAndRunMultipleSimulators.sh
script:
-
Update the variables
-
Update the simulators by name or identifier
d. Open Run destinations Cmd+Shift+2 then do the following:
a. Select Simulators and click (+) to add a new run destination
b. Name the simulator iPhone15+MultiSim
or anything you like. You will need this name later
c. Select iPhone 15 for the Device Type
d. Click Create
e. Go to Project Navigator, then select the Project, then select the Target.
- In Build Phases tab, add a new Run Script and paste the code below.
custom_sim=`xcrun simctl list | grep 'iPhone15+MultiSim' | awk -F'[()]' '{print $2}'`
if [ ! -z "${custom_sim}" ] && [ "${TARGET_DEVICE_IDENTIFIER}" = "${custom_sim}" ]; then
/bin/sh buildAndRunMultipleSimulators.sh
fi
-
If you named your script to something else, then update the filename in the script
-
If you named your simulator to something else, then update the name in the script (
grep 'iPhone15+MultiSim'
) -
You can also rename the run script
f. Select iPhone15+MultiSim as your simulator and run the project.