Running your app in Simulator
Simulator is installed when you install Xcode. It provides a simulated iOS device so that you can see what your app looks like and how it behaves, without needing a physical iOS device. It can model all the screen sizes and resolutions for both iPad and iPhone so you can test your app on multiple devices easily.
To run your app in Simulator, follow these steps:
- Click the Destination pop-up menu to view a list of simulated devices. Choose iPhone SE (3rd generation) from this menu:
Figure 1.16: Xcode Destination pop-up menu with iPhone SE (3rd generation) selected
- Click the Run button to install and run your app on the currently selected simulator. You can also use the Command + R keyboard shortcut.
- Simulator will launch and show a representation of an iPhone SE (3rd generation). Your app displays a white screen, as you have not yet added anything to your project:
Figure 1.17: iOS Simulator
- Switch back to Xcode and click on the Stop button (or press Command + .) to stop the currently running project.
You have just created and run your first iOS app in Simulator! Great job!
Now, you may be wondering what the Devices and Build sections in the Destination menu are used for. Let’s look at them in the next section.
Understanding the Devices and Build sections
You learned how to choose a simulated device in the Destination menu to run your app in the previous section. In addition to the list of simulated devices, this menu also has Devices and Build sections.
These allow you to run apps on actual iOS devices and prepare apps for submission to the App Store.
Click the Destination menu in the toolbar to see the Devices and Build sections at the top of the menu:
Figure 1.18: Xcode Destination menu showing Devices and Build sections
If you have an Apple Silicon Mac, the Devices section will display text stating My Mac (Designed for iPad), because Apple Silicon Macs can run iOS apps. Otherwise, No Devices will be displayed. If you were to plug in an iOS device, it would appear in this section, and you would be able to run the apps you develop on it for testing. Running your apps on an actual device is recommended as Simulator will not accurately reflect the performance characteristics of an actual iOS device and does not have hardware features that actual devices have.
The Build section has two menu items, Any iOS Device(arm64) and Any iOS Simulator Device (arm64, x86_64). These are used when you need to archive your app prior to submitting it to the App Store. You’ll learn how to do this in Chapter 27, Testing and Submitting Your App to the App Store.
Now let’s see how to build and run your app on an actual iOS device. Most of the instructions in this book do not require you to have an iOS device though, so if you don’t have one, you can skip the next section and go straight to Chapter 2, Simple Values and Types.