Xcode Simulator App Advanced

In this tutorial, you’ll learn about Xcode Simulator’s advanced features to improve your daily development experience. By Vidhur Voora.

Leave a rating/review
Download materials
Save for later
Share

The Xcode Simulator is one of the tools used most widely by developers. Running and testing apps on the simulator has become part of every developer’s daily routine. Becoming familiar with various simulator options is vital for any developer. Did you know you can create and configure simulators from the command line as well? In this tutorial, you’ll learn:

  • What a simulator is
  • Insights into useful simulator options
  • To create and configure simulators from the command line
  • To stream and capture logs using the command line
  • To create a Bash script to automate launching the app on a simulator in different locales.

Getting Started

Download the project by clicking the Download Materials button at the top or bottom of this page. Open the RayWonders project. Build and run.

Advanced Simulator walkthrough

This app has two tabs — Photo and Map. The Photo tab shows photos of the wonders of the world. Tapping a photo shows a detailed view of its description. The Map tab shows the photos of the wonders of the world as annotations on a map. This is one of the rare raywenderlich.com tutorials where you won’t be modifying the project. Instead, you’ll use this app as a foundation to learn the various simulator options. Before you embark on your world tour, you’ll need to understand what a simulator is.

What Is a Simulator?

The simulator is a great tool to simulate iOS, iPadOS, tvOS, and watchOS on the Mac. It helps rapid prototyping and testing builds by simulating different devices. At a more technical level, a simulator is a separate user space running on the macOS kernel.

Simulator architecture

User space is the system memory allocated to run applications, whereas kernel space is the system memory allocated to run the OS kernel and device drivers. Launching a new simulator creates a separate user space.

The kernel is a core component of the OS. It facilitates interactions between the hardware and software components. It’s responsible for managing the hardware, allocating memory and arbitrating between processes.

One of those processes — Daemon — runs in the background. launchd, cfprefsd, distnoted are some of the system daemons.

Are running an app on a device and on a simulator the same? You’ll learn that next.

Running App on a Device vs. a Simulator

Testing apps on a simulator is very handy. However, there are a few key differences between running apps on a device and on a simulator.

Computing Performance

Simulators share the same computing resources with the Mac. This includes memory, CPU and network connection. In contrast, physical devices have less memory and computing power compared with a Mac. Also, the network can be one unpredictable beast on the physical device.

Device performance vs Mac performance

Display

The resolution and the color gamut on a Mac and the physical device can differ, causing images and text to appear jagged. You’ll learn how to simulate the exact physical device size later in this tutorial.

Hardware Limitations

Some hardware components are not supported in a simulator. These include:

  • Bluetooth
  • Camera
  • Motion sensors such as accelerometer and gyroscope
  • Proximity sensor

Framework Limitations

A few frameworks are not supported in simulator. These include:

  • ARKit
  • HomeKit
  • IOSurface
  • MessageUI

For a more exhaustive list of all the differences, please refer to the documentation by selecting Help ▸ Simulator Help in the Simulator menu.

Next, you’ll learn how to organize the simulators.

Organizing Simulators Using Xcode

Xcode ships with a default set of simulators. To view a list of these simulators, follow these steps:

Device and simulators in Xcode

  1. Open Xcode.
  2. Select the Window menu option.
  3. Choose the Devices and Simulators menu.
  4. Select the Simulators tab.

You’ll see a list of simulators that were shipped with Xcode. If you’ve downloaded other runtimes in the past, you’ll see those associated simulators as well.

Now, you’ll create a new simulator with a custom name.

Create simulator from Xcode

Follow these steps:

  1. Press the + button at the bottom left.
  2. Set the simulator name as Demo.
  3. Select iPhone 12 Pro as the device type.
  4. Select iOS 14.2 as the OS version.
  5. Press Create.

This creates a new simulator with the name Demo, which you can now find in the list of simulators.

Uncheck the Show as runtime destination checkbox for the Demo simulator.

Hide simulator option

This hides the simulator. It won’t show up in the list of simulators next to the app scheme.

Control-click the Demo simulator. Several options appear, such as Delete and Rename.

Delete simulator context menu

Go ahead and delete the Demo simulator by clicking Delete. Don’t worry; you’ll create it using a different method very soon.

Running Older Runtimes

Sometimes you’ll have to run your app on older versions of runtimes.

Download runtimes menu

You can download older runtimes by selecting Download more runtimes in the OS Version drop-down when creating a new simulator.

You can also download more runtimes from the Components window. Select Xcode ▸ Preferences ▸ Components option.

Simulator components window

This window shows the list of the downloaded simulator runtime as well as other runtimes available for download.

Next, you’ll learn an alternative way to create simulators.

Creating Simulators From the Simulator Menu

Build and run.

When the simulator is running, follow these steps:

Create simulator from menu

  1. Select File ▸ New Simulator from the Simulator menu.
  2. Enter Demo as the simulator name.
  3. Select iPhone 12 Pro as the Device Type.
  4. Select iOS 14.2 as the version.
  5. Click Create.

Open the simulator by following these steps:

  1. Select File ▸ Open Simulator from the menu.
  2. Select the iOS 14.2 run time.
  3. Choose the Demo simulator.

Demo simulator

This launches the Demo simulator.

That was fast and easy! Next, you’ll learn about the various size options in the simulator.

Comparing Simulator Size Options

You can resize a simulator by clicking and dragging from one of the four corners. The Window menu options provide four scaling options.

Physical Size

Simulator in physical size mode

Physical size resizes the simulator to match the actual device size. This visualizes how your app looks across different screen sizes.

Point Accurate

Simulator in point accurate mode

Point accurate mode sizes the window so that the content has the same size on devices with different scale factors. As a result, an image on a device with a 3x display appears with the same size as a 2x display.