1.4. Running iOS Apps on the Simulator

Problem

You’ve prepared an iOS project in Xcode and would like to run it in iOS Simulator to make sure it works.

Solution

You need to use the Scheme breadcrumb button on the top-left corner of Xcode to first select the project that you wish to run on the iOS Simulator and then select the simulator that you wish to run your app on (iPhone/iPad).

Discussion

Follow these steps:

  1. Find the Scheme breadcrumb button on the top-left corner of Xcode’s window. This button looks like that shown in Figure 1-11.

    The Scheme breadcrumb button in Xcode

    Figure 1-11. The Scheme breadcrumb button in Xcode

  2. In Xcode, you can have multiple projects on the same workspace. For example, at the time of writing this recipe, I have one project per recipe, added to one big project that I’ve created for this book. The left side of the Scheme button shows you the project that’s currently selected. So if I click on the left side of the Scheme button, I’ll see something similar to Figure 1-12. So go ahead and click on the left side of the Scheme button and select the project that you wish to run on the iOS Simulator.

  3. The right side of the Scheme button lets you choose which device/simulator you wish to run your app on. I’ve selected iPhone Simulator. Go ahead and press the right side of the Scheme button to select which simulator you would like to run your app on (Figure 1-13).

The project currently selected

Figure 1-12. The project currently selected

Note

Bear in mind that the options presented to you on the right side of the Scheme button depend entirely on how your project is set up. In the second stage of creating an iOS Project, Xcode asks you which device(s) you would like your app to run on (in the Device Family drop-down). You can see this box in Figure 1-2. A Universal app is an app that runs on both iPad and iPhone. There are also options to select to make your app run only on iPhone or only on the iPad.

Selecting the iPhone Simulator

Figure 1-13. Selecting the iPhone Simulator

Now that you have selected which simulator you would like to run your app on, simply go to the Product menu in Xcode and select Run. Xcode will compile your app (Recipe 1.3) if it’s not compiled yet and will then run it on your selected simulator.

See Also

Recipe 1.3

Get iOS 6 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.