iOS Handle Multiple Environment using Macro Handle multiple environment using multiple target and macro

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

For example, we have two environments: CI - Staging and want to add some customizations for each environment. Here I will try to customize server URL, app name.

First, we create two targets for 2 environments by duplicating the main target:

Create targets

For each target, we will define a custom macro. Here I will define macro named "CI" in build settings of target CI, macro named "STAGING" for target Staging.

The development target (MultipleEnvironment target): DEV

Target CI:

enter image description here

Target Staging:

enter image description here

Create scheme for each target: enter image description here

We will create a header file to define SERVER URL as below:

enter image description here

It means,

If you want to do more customize, for example: Change app name for each target:

enter image description here

enter image description here

Almost done. Now we want to show current SERVER_URL to main screen: enter image description here

Now, let's see if we run the app with the default target (MultipleEnvironment) enter image description here enter image description here

CI target:

enter image description here enter image description here

Staging target:

enter image description here enter image description here

As you can see, value of SERVER_URL and app name is changed for each target :)



Got any iOS Question?