Xcode is an advanced IDE (Integrated Development Environment) and it isn't always obvious how to perform seemingly trivial tasks, such as adding a scheme. In this post, I show you in a few simple steps how to add a scheme in Xcode.
Creating the Project
Fire up Xcode and create a project by choosing the New > Project... from Xcode's File menu. Choose the App template from the iOS > Application section. You can skip this step is you already have a project to work with.
Give the project a name. It doesn't matter whether your project uses UIKit or SwiftUI. That's irrelevant for what follows.
Exploring Schemes in Xcode
The active scheme is displayed in Xcode's status bar at the top. When you create a project, Xcode creates a scheme for you. The name of the scheme is identical to the name of the project, Notes in this example. The active scheme is followed by the destination, an iPhone 14 simulator in this example. Click the play button on the left to start the active scheme.
Click the active scheme. We currently have one scheme. We can edit it, add a scheme, or manage the scheme of the project. Since we want to add a scheme, click New Scheme... from the menu.
Adding a Scheme to the Project
Let's create a scheme to simulate that the application is being used in a different region. This can be convenient to quickly switch between regions. Name the scheme Notes-Australia.
Note that the new scheme is the active scheme. Click the active scheme to see the list of available schemes. Click Edit Scheme... to edit the scheme.
Choose Run on the left and select the Options tab. Scroll down to App Region and set it to Australia.
Let's see if it works. Click Close in the bottom right and open ViewController.swift. In the view controller's viewDidLoad()
method, we safely access the region of the current locale. We print the region's identifier to the console.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let region = Locale.current.region {
print(region.identifier)
}
}
}
Build and run the application and inspect the output in the console at the bottom. You can access the console by pressing Option + Shift + Y or clicking the Show the Debug Area button at the bottom.
The identifier printed to the console confirms that Xcode set the region to Australia.
AU
To prove that I'm not located in Australia, we set the active scheme to Notes, the scheme Xcode created for us. Build and run the application one more time and inspect the output in the console.
US
Even though I'm based in Belgium, I typically set the region of my machine to US and the language to English hence the output in the console.
Using Multiple Schemes in Xcode
It can be useful to define multiple schemes for a range of reasons, including creating release builds, switching environments during development, and testing. You can configure a scheme however you like so it pays to spend some time setting up the schemes of your project to fit your needs.