Building an App

It’s a rite of passage for developers learning new things to make a Hello World app. In this section, you’ll do just that. You’ll also see all the steps you need to set up an app project and get it to run on a simulator. These general steps are the same if you’re making Hello World or writing the world’s greatest task tracker.

App Templates

Start a new project from the initial Welcome to Xcode screen or using File ▸ New ▸ Project… and you’ll see the template chooser. There’s a template chooser for each file, which you saw earlier. This is a template chooser for an app project.

Xcode templates provide basic files and configuration.
Xcode templates provide basic files and configuration.

In these templates, Apple provides a minimum set of files to make particular kinds of apps. These templates focus on providing you with something that you can build quickly.

Some of the code doesn’t follow best practices because that would make the initial app more complicated. In most cases, you’re going to erase the provided code anyway. Use the code in the templates as a starting point. Don’t use coding patterns from the templates in your own apps without researching first.

App Options

After you choose which template to use, you’re faced with another set of choices. These options can impact this app for its entire lifetime, and some are difficult to change. So, it’s essential to give some thought here.

Options dialog for naming the app and choosing a bundle identifier
Options dialog for naming the app and choosing a bundle identifier

Let’s see what each field means one by one:

  1. First, you’ll give your app a name. This is the project’s name, the file folder on your hard drive, and even the app’s display name on your phone. You can change the display name later. You can also change the project name later, but it’s complicated.

  2. The next option is the team. Since you’re just starting, you can leave this blank. If you’re already on a team through work or because you’ve subscribed to the Apple Developer Program, you’ll add it here. Xcode will communicate with Apple’s servers and download some certificate files for that team to link this app to the team. If you’re on more than one team, be careful to choose the right one. You don’t want to accidentally assign your secret side project to your company.

  3. Organization Identifier is perhaps the most essential choice you must make here. This identifier must be unique. The custom is to use a web domain you own in reverse. The identifier will be associated with the team if you’ve chosen one. You can’t change it once it’s created. If you modify it later, you’ll have created a new one, rather than changing the original. Also, if someone not on your team has already taken it, you can’t use it.

  4. The Organization Identifier, along with the app’s name, will become the Bundle Identifier. The Bundle Identifier uniquely identifies your app on an iOS device. Once you deploy an app with this identifier, if you deploy another app with the same identifier, it’ll overwrite the first app. The identifier is only for you and Apple to know. Regular users of your app won’t know what it is.

The next options are less critical. They only control some pieces of the app template’s inital configuration. For instance, the storage option will add SwiftData or Core Data template files to your app and modify the template to use a little database. Similarly, if you check the Include Tests option, Xcode will add some test files to your project. After you set everything up, click Next to move to the next step.

Leave Create a Git repository off if you've not set up Git.
Leave Create a Git repository off if you've not set up Git.

If you don’t have Git on your computer, uncheck the Create Git repository on my Mac option. You can always add source control later, but Xcode will complain if you check the box, but Git isn’t configured. After you’ve chosen a location, click Create.

App Interface

Now, your Xcode workspace is ready to go.

Your new SwiftUI Hello World app with previews and sample code
Your new SwiftUI Hello World app with previews and sample code

The project navigator on the left shows the current file: ContentView. In the main editor window, you’ll see the code that makes up ContentView and, next to that, a preview of what the code will look like on an iOS device. This is the preview canvas. It’ll appear when you have a SwiftUI file in your editor with a #Preview macro. You can see the macro for this file at the bottom.

New Controls

At the top of the window, notice a new toolbar. This wasn’t visible in the previous section because it only appears when you’re working on an app. On the toolbar’s far left and far right, there are two buttons to show and hide the navigators and inspectors, respectively.

You’ll also see a play button like you’d find on a music player. Clicking this button is a shortcut to build and run your app on a device. It’ll run on the device listed on the toolbar, the iPhone 15 Pro simulator. To the right of that is the current status. When Xcode is building or performing another long task, you’ll see the progress over there.

Project Settings

For a moment, turn your attention to the project settings for this app. These settings control things like what kinds of devices your app runs on and the minimum version of the OS you’ll support.

General project settings shows platform destinations, app name, and minimum iOS requirements. Version and build numbers are also displayed.
General project settings shows platform destinations, app name, and minimum iOS requirements. Version and build numbers are also displayed.

Here’s where you set your app’s Display Name. The Display name is the word underneath your app icon on your users’ devices. There’s not much space there, so your app’s name will get truncated if it’s too long. An app with a truncated name doesn’t look very professional.

You’ll also notice your bundle identifier again. Below is where you set your version and build numbers for the app. You can start with any number you like, but you must always increment them when you deploy. If you deploy a new version of your app but don’t change the version numbers, iOS will quietly not install it on your users’ devices because it assumes they already have it.

This screen is also where you can set your app’s launch screen and the app icon. You can configure what orientations your app supports from this screen as well.

The Signing & Capabilities tab shows certificates this app uses and a button for adding entitlements.
The Signing & Capabilities tab shows certificates this app uses and a button for adding entitlements.

The Signing & Capabilities screen is another screen you’ll revisit when working. A signing certificate is an encrypted file that Apple issues to your app. It ties your app’s identity to your team’s identity to you. Without a signing certificate, you can’t build your app for a device; you can only run it on the simulators.

A signing certificate has more information: your app’s capabilities or entitlements. When you want to work with Siri on your users’ devices or access passes in their wallets, or several other services on the phone, you have to add the capability to your certificates. Without that, when you try to access those services, iOS on your users’ devices will block your app and, in the worst case, crash your app.

Editor

Returning to this app’s main code editor area, you’ll see the word globe on the left. This is the name of an SF Symbol. You can change globe to any other SF Symbol name, and a new icon will appear in the preview.

The same is true for “Hello, world!”. If you change that text, the preview changes. The preview reacts to your code in real time. Sometimes, when there’s a bug in your code and the app can’t build correctly, the preview won’t appear.

Though changing the code can impact the preview, you can also use the Attributes inspector. For instance, select the line Text("Hello, world!") and then open the Attributes inspector. Change the font and the padding using the attribute controls. Once you’ve done that, you’ll see that the inspector has updated your code.

Changes to the code or inspector update the other in real time.
Changes to the code or inspector update the other in real time.

Here, you can see that the font changed to Large Title in the inspector. The preview shows the larger font, and the code has updated to add a font(.largeTitle) modifier to the Text object.

Build and Run

Once you’ve configured your project settings, written your code, and perhaps added media assets like an app icon, you’ll finish by building your app and running it on a simulator.

Currently installed simulators, physical devices, and generic build destinations
Currently installed simulators, physical devices, and generic build destinations

As much as they’d like all of the developers in the world to buy multiple devices for testing, Apple knows that most can’t do that. So, Xcode provides simulators for all Apple devices. You can select any of the current devices. In a later lesson, you’ll learn how to download simulators for some older devices, which is helpful when your users report a problem, but only on a specific model of phone or version of iOS.

The preview window showed how a single view looks, but with the simulator, your entire app runs just like on a device. There are a few things that you can’t test on a simulator, like the camera. But most of the time, you can be confident that if your app runs on the simulator, it will run the same way on real devices. Once you’ve chosen a simulator, click the play button or use the Product ▸ Run menu option.

You’ll see the progress indicator as Xcode builds your app. Then, you’ll see the simulator launch. The first time you run an app on the simulator, it takes an extra long time since files are copied and installed, and Xcode adds debugging probes. Finally, though, your app appears!

Your Hello World app running in the iPhone 15 Pro Max simulator
Your Hello World app running in the iPhone 15 Pro Max simulator

Workflow

That’s the general workflow for building an app. You’ll need to make some initial decisions about naming, what capabilities you want, which OS versions you support, and other setup. Then, you’ll write your code, adding more source files as your app gets more complicated. Finally, you’ll choose a destination and build your app to test it. In the demo, you’ll see all of this in action.

See forum comments
Download course materials from Github
Previous: Xcode Tour Demo Next: Basic Workflow Demo