DEV Community

Michael Mavris
Michael Mavris

Posted on • Originally published at rockandnull.com on

How to create a white label iOS app (Part 3)

As we discussed on Part2, it's not recommended to create duplicates of the same class with different target membership.

You can download the project here as we left it on Part2.

We could tackle this issue using Preprocessor flags, which will allow us to add conditions based on which target the app is running. Go ahead and delete the Coffee class under RealCoffee. Then go to Coffee class under the TestCoffee folder and check the RealCoffee target under Target Membership.

How to create a white label iOS app (Part 3)
Coffee class is now recognised by both targets

Now we need to set an identifier for each Target. Will set this identifier under Build Settings -> Active Compilation Condition for both identifiers. Use TESTCOFFEE and REALCOFFEE for both Debug and Release.

How to create a white label iOS app (Part 3)

Now head to the Coffee class and modify the coffeeDescription as follows:

static func coffeeDescription() -> String {
     #if TESTCOFFEE
        return "TestCoffee"
     #elseif REALCOFFEE
        return "RealCoffee"
     #else
        return "WRONG"
     #endif
}

It's clear from the code that the response from the coffeeDescription function will depend on the target. If the response is "WRONG" then something went wrong setting the Active Compilation Conditions.

I personally don't like using Preprocessor flags for the coffeeDescription function because it won't scale. Imagine having 30 targets and having 30 Preprocessor flags for each one. I just wanted you to know that you have that option! Use with caution.

Happy coding!

How to create a white label iOS app (Part 1)
How to create a white label iOS app (Part 2)
How to create a white label iOS app (Part 3)
How to create a white label iOS app (Part 4)
How to create a white label iOS app (Part 5)

Latest comments (0)