Setup an IOS Environment — debug , release and staging.

Jayant Kumar🇮🇳
4 min readFeb 3, 2024
Photo by zero take on Unsplash

In this article we will see how to setup debug , release and staging environment in iOS development. we will also see where we keep our secret keys (for eg- base url) of each environment.

DEBUG (development env.)

This environment is used by us (developer) to develop and test the application.

STAGING (testing env.)

After development , we will give staging environment’s build to tester for testing.

RELEASE (production env.)

This environment’s build will be deployed on the Apps Store

By default there will be two environment in any iOS project. i,e, Debug and Release

When you click on the root project folder , you can see it.

By default , debug env. is selected. It means we run the application in debug mode.

First let’s add one more environment i,e, Staging

Now we have three environments in the application.

Let’s see how we can run the application in any of the environment (debug , staging , release).

As you can see in the above video , we go to Product → Scheme → Edit scheme and change the build configuration to any of the environment. Your application will run at that environment.

Suppose I want to change the app name of each environment (debug , staging and release) .

As you can see above , we go to Targets → Build Setting → Search Product Name and we have debug , staging and release app’s name. If you want to change to any other name , you can change from here as well.

Let’s come into the most important part how to secure and keep the Base Url and other sensitive information of each environment.

Suppose you have three base url for each environment and you want when you switch to any of the environment , base url automatically switched to that environment.

To do that you have to create three Configuration Settings File (debug , staging , release) , where we keep our Base Url.

Step — 1

  • As you can see above , First we click on New File → Search Configuration Setting File and create a Config_Debug file.

Step — 2

  • In the same way you create other two Configuration Setting File (staging and release).
  • Open these file and write the Base Url
PROTOCOL = https/
BASE_URL = ${PROTOCOL}/:www.debug.com
PROTOCOL = https/
BASE_URL = ${PROTOCOL}/:www.staging.com
PROTOCOL = https/
BASE_URL = ${PROTOCOL}/:www.release.com

Step — 3

After that assign these Setting Configuration file to each environment, I mean →

Config_Debug → debug env

Config_Staging → Staging env

Config_Release → Release env

As you can see above we go to Project → info tab and set these configuration files.

Step — 4

As you can see above , when you go to Project → Build Settings → Basic → User-Defined. BASE_URL section is automatically created and we have corresponding values of each env.

Final Step

The final step is to define this BASE_URL to info.plist file , so that we can access the value of BASE_URL in the project.

As you can see above we go to Targets → Info and we defined a key called BASE_URL , and the value will be your ${BASE_URL} , which we are getting from the User-Defined section of the previous step.

we will use this BASE_URL key in the project to get the actual value.

Access the Base Url In the Project

struct TestScreen : View {

var baseurl:String = Bundle.main.infoDictionary?["BASE_URL"] as! String

var body: some View {
VStack{
Text(baseurl)
.font(.title2)
}
}
}

As you can see above we are on the staging environment , that’s why we get the staging Base Url.

Conclusion

You can define as much as secret keys in the Setting Configuration file. From my point of view this is the best solution if you have multiple environments with different values. You can get rid from hardcoding the Base Url or changing the url every time when you switch the environment.

So That’s all for today’s my friends hope you enjoyed and learnt something new from this article. If you have any queries or suggestion do let me know in the comment section.

--

--

Jayant Kumar🇮🇳

Hello , My name is Jayant, I am a tech youtuber and software Engineer from India 🇮🇳