How to manage different environments using XCode schemes

Have you ever felt lost when you were asked to release a new version from your iOS application? You have to double-check that you used all the production URLs and API keys. Right then, you feel the fear that you missed updating one or more of those values. If you have that pain? Then, I believe that now is the right moment for you to know about the XCode scheme to save your life and your time managing your project environments.

Photo by Christopher Gower on Unsplash

In this article, we will go through these points:

  • How to add new multiple Schemes to your project?
  • How to have corresponding configuration files with each different Schema?
  • How to set up a Firebase project for your schemes?

What is the diff between Xcode Target and Scheme?

A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. A target defines a single product; it organizes the inputs into the build system — the source files and instructions for processing those source files — required to build that product. Projects can contain one or more targets, each of which produces one product.

In other words, each target defines one scope of the app. Imagine that you are implementing an app with pro features and free features. Xcode Targets will save the situation by implementing two targets. A target for the default/free mode and another one for the pro version.

An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute. You can have as many schemes as you want, but only one can be active at a time.

This article focuses on the Xcode Schemas. It shows how to handle multiple configurations with multiple schemes. It is worth mentioning that if you are using more than one target, each one of them must include at least one Scheme.

How to add new multiple Schemes to your project?

First of all, you need to open the manage scheme dialog from the top left of Xcode, as shown in Figure 1.

Figure 1.

You have to click the + button in the bottom left corner to create a new scheme, as shown in Figure 2.

Figure 2.

Then create two new schemes as shown in Figure 3 [Staging and Production].

Figure 3.

By creating we have 3 Schemes:

  1. The Default Scheme is used as a development scheme.
  2. The Staging Scheme for QA and testing purposes.
  3. The Production Scheme for the App store.

Now, the time has come to adjust the corresponding configuration modes. Currently, we already have two configuration modes in our project: Debug and Release. We need to add a new configuration mode for the Staging. To achieve that, you have to click on the + button, as shown in Figure 4.

Figure 4.

Figure 5. shows the three configuration modes we have: Debug, Staging, and Release. The next step is to add three configuration files. Those Configuration Settings files will be considered the default values for each corresponding mode.

Figure 5.

How to have corresponding configuration files with each different Schema?

Figure 6. shows how to add a new Configuration Settings file.

Figure 6.
Figure 7.

After creating the three Configuration Settings files, we need to connect them to the correct Schema. Figure 8. shows how we can accomplish that by visiting the Project Info section.

Figure 8.

So far, so good? Yeah, exciting! We have three schemas with three configuration settings files. Let’s leverage!

In Figure 9. we added one Configuration variable with three different values.

Figure 9.

Wroth mentioning that we need to have three different Provisional Profiles. To have three instances of your app, you have to update the Build Configuration via clicking Manage Scheme Button. Please check Figure 10.

Figure 10.

You have to highlight different and unique Bundle Identifiers for each Schema — figure 11.

Figure 11.

To confirm that everything went well, please check the Signing & Capabilities section. You should be able to see the app’s three different instances, as shown in Figure 12.

Figure 12.

Last but not least, we can use the added Configuration Variable BASE_URL. You can do add it to the info.plist. Afterward, you can use it wherever you want in your code.

Figure 13.
Figure 14.

Now, you have just seen how we fetched the correct BASE_URL value according to the selected Schema Yaay! 🎉

Next step? How to set up a Firebase project for your schemes?

After you create your new Firebase Project, add three iOS apps inside this project. Add the Bundle Identifier for each one of them. By then, you will have three GoogleService-Info files, then rename each of them as shown in Figure 15.

Figure 15.

Subsequently, add value for it inside the xcconfig file as shown in Figure 16.

Figure 16.

Then add value for it inside info.plist file to readable inside your swift code as shown in Figure 17.

Figure 17.

Figure 18. shows how to use this value inside AppDelegate.swift

Figure 18.

Finally, you can hit the run button and …… Tada! 🎉 Congratulations, now you have an application with three customizable schemes and three corresponding Firebase apps. Moreover, you can receive push notifications for them or track the crashes for each of them individually.

I recommend watching this handy video.

This article was part 1 of my future-to-be series of methodologies to facilitate my daily working life. Stay tuned!

iOS Team Lead — Mobile App Developer @ TrianglZ LLC | Swift | apple | Lifelong Learner | Fifa player

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store