How To Create Multiple Versions Of Your iOS App In Xcode Part 1

You want to create multiple versions of the same iOS app with slight differences?

For our language learn apps, we had exactly this problem. We had one app to learn Thai, and we wanted another build of the same app to learn Chinese.

So these two apps should have the following differences:

  • Different app names
  • Different bundle ids
  • Different database loaded (Chinese words vs. Thai words)
  • Different app icon
  • Different assets within the apps, such as icons and audio files

Let’s tackle these issues step by step.

1. Create new configurations for each app

First you need two create a new configuration for the debug version of your app and one for the release version of your app.

In Xcode, open your project infos by clicking on your project root folder in the project navigator. On the left side, select your project. Make sure that “Info” is selected on the top. Under “Configurations”, press the “+” to duplicate your existing debug configuration. Then press the “+” again to duplicate your existing release configuration.

test_xcodeproj

For our example, we will name the configs “Thai Debug”, “Thai Release”, “Chinese Debug” and “Chinese Release”.

2. Adjust the configuration settings

Now we need to adjust the settings of each of these configurations to reflect the differences in both apps.

For the sake of simplicity, we change the settings directly in Xcode. (If you want to use .xcconfig files instead, I highly recommend going through this tutorial first.)

Change the Bundle Id: Make sure the root folder in the project navigator is selected. On the left side, select your project target. Select “Build Settings” on the top and make sure that “All” is selected (as opposed to “Basic”) . Search for “Product Bundle”. In the “Product Bundle Identifier” section, give the different configs the following identifiers: “com.example.thai” for “Thai Release”, “com.example.thai.debug” for “Thai Debug”, “com.example.chinese” for “Chinese Release” and “com.example.chinese.debug” for “Chinese Debug”.

Change the App name: Again, select the “Build Settings” on the top and search for “Product Name”. In the “Product Name” section, change the names to “Learn Thai”, “Learn Thai Debug”, “Learn Chinese” and “Learn Chinese Debug”.

Create user defined values: Because we want to load different data into each app, we need to define a custom variable that we will access in our Swift code later on.

In your “Build Settings”, click on “+” and then “Add user-defined setting”. We will name the new setting LANGUAGE_CODE and name it th for both Thai configs and zh for both Chinese configs.

Create Swift flags: But that’s not enough. In order for Swift to be able to read our variables, we need to define Swift flags. In your “Build Settings”, search for “Swift Flags”. Under “Other Swift Flags”, give all your configurations the following value: -D ${LANGUAGE_CODE}

Now you should be able to use your flags th and zh for both languages in your code.

3. Read your settings in the Swift code

Create a new Swift class called BuildConfig that looks like this:

import Foundation

class BuildConfig {    

    static var currentCulture: Culture {

        get {

            #if zh

            return Culture.Chinese

            #elseif th

            return Culture.Thai

            #endif

        }

    }

}

Culture is an enum containing the parameters of your build. From now on, you can easily check your build variant in your code. For example, you can check if BuildConfig.Culture == Chinese and load the according data from the database.

4. Done – Almost!

By now, your apps have different bundle names and app names. Also, you can use the BuildConfig class to implement differences between your apps directly in your Swift code.

Now it would be nice to load different assets such as launch icons, in app icons or audio files into each app.

This is a bit tricky, and I will cover this in part 2 of this tutorial.

6 thoughts on “How To Create Multiple Versions Of Your iOS App In Xcode Part 1

    1. Hey Craig, interesting thought! That might save some the scripting in part 2 of the post. But for app name, app bundle and launch icon I’d still need different configurations right?

      Like

  1. Anonimo scrive:ciao a tutti.ikaro mi è stato d’aiuto grz mille.ho una do0#cda&a823m;nosa vuoil dire (N) nelle router???ho visto in alcuni route ce portato 150n o 300n cosa vuil dire??è importante come funzione??se pui rispondi perfavore,

    Like

  2. Hi Simon,
    Everything looks good. But the only and major hindrance is I am new to iOS and I am doing it in Objective-C. Unfortunately for me, your blog follows Swift. I am not knowledgable enough, yet, to read your Swift code and find the corresponding same functionality in Objective-C.

    Hence, if you could help me out by posting code in objective-C or atleast provide some links to other blogs that achieves different build variant implementation using objective-C, it would really be very very very helpful.

    Thanks.
    P.S:- I searched quite a lot on the internet for this, using objective-C but most of the results I got are in Swift. And the ones in objective-C did not work 😦

    Like

Leave a comment