Freelancing for Pale Blue

Looking for flexible work opportunities that fit your schedule?


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

iOS Aug 29, 2020
How to create a white label iOS app (Part 2)
How to create a white label iOS app (Part 1)If you are a developer in a companythat is developing software for its productsonly, then you probably won’t be familiar with the “White-label” term. Awhite-label app is a product produced by one company then packaged anddistributed by other companie…

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.

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.

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!

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.