Launch multiple simulators — XCode 12

Guilherme Girotto
4 min readOct 11, 2018
Multiple Simulators Launch Demo

One of the major iOS developer's challenges it's to test auto-layout in all available iPhone's screen sizes. Nowadays, if you follow Apple's recommendation to support all devices since iOS 12, you need to make your layout available in at least 5 screen sizes:

  • iPhone SE
  • iPhone 6/6s/7/8
  • iPhone 6/6s/7/8 Plus
  • iPhone X/XS
  • iPhone XS Max

With all these screen sizes, we must ensure that the layout will fit each one of them. But this task is painful due to the different simulators sizes that you've to instantiate to test your layout. That's why this script may help you save a lot of time.

# Create a Custom Simulator

First of all, we must create a new simulator that will be the one that will be the one which will launch all simulators together when building your project. For this go to Products -> Scheme -> Edit Scheme

Scheme edition

Open Build at the left menu, create a new Pre-Action script and paste the following script

Custom Simulators script

Now build your project and you may see a new simulator at the top of the list named Custom Simulators. This script creates a new custom simulator which will be the one that will hold all the simulators that you desire to run simultaneously. Note that this script uses one of the existent iOS simulators as the base simulator. In this example, it uses iPhone X as the base simulator. It means that Custom Simulators will run the iPhone X simulator and after the other simulator that you want to.

Custom Simulators at simulators list

# Create Simulators List File

This is the file that will hold all identifiers from the simulators that will be launched when running Custom Simulators simulator. Create a file namedSimulatorsList.txt at your project root directory, and list all simulators identifiers that you want to be launched. Note that the more simulators you launch more memory and CPU are used.

To get the simulators identifier open your Terminal and run instruments -s devices. This will list all available simulators and its respective identifiers. They will appear in the following format:

iPhone Model (iOS version) [IDENTIFIER] (Simulator)

We are only interested in the simulator identifier, so for all simulator that you want to launch simultaneously, copy the identifier between the brackets and paste them in the SimulatorsList file, one at each line.

Simulators List example

# Create Launch Script

This script will be the responsible for reading and launching all simulators with identifiers listed at SimulatorsList.txt and installing and launching your app in each one of them. For this, create multipleSimulatorsStartup.sh at your project root directory and paste the following script

Simulators startup script

The script itself has comments to describe which each command does. Don't forget to replace <YOUR_PROJECT_NAME> with your project name, <YOUR_APP_NAME> with the name of the executable of your app (if you don't know it, you can check by going through the $path folder structure) and <YOUR_PROJECT_BUNDLE> with the bundle of your project.

You may face yourself with your project files structure like this.

Project root directory structure

# Create Run Script

The final step is to create a Run Script to run this recently created script if the chosen simulator is Custom Simulators. Select your project target and go toBuild Phases and create a new Run Script.

Build Phases script

And paste the following script.

Done!

And it's done! Now, you can run your app target using Custom Simulators and see all simulators launching and running together. It may take a look to launch all simulators, it depends on the number of simulators you've chosen.

For those who need, here is an example project that follows all steps from this tutorial. This example project uses XCode 12 simulators, you need to change the simulators identifiers at SimulatorsList.txt . You can download it here https://github.com/ggirotto/MultipleSimulators

Please consider leaving a comment/feedback :)

--

--