

How to set Info.plist Values based on Build Configuration in Xcode
source link: https://sarunw.com/posts/set-info-plist-value-per-build-configuration/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to set Info.plist Values based on Build Configuration in Xcode
Table of Contents
Info.plist is a file that contains information about an app, e.g., app name, app version, or even API Key for third-party service.
If you use build configuration to separate setting between development, stating, and production, you might want to configure Info.plist value based differently based on build configuration.
In this article, we will learn how to do that.
I will give you two examples.
- Setting a value that Xcode already provided. I will set a different app's name based on the build configuration.
- Setting a custom value. I will set an imaginary API key.
Setting a predefined value
If you open Info.plist or Info tab, under the "Bundle name", which is a key for the app name, you will see the value set to $(PRODUCT_NAME)
.

Dolla sign ($
) and a build settings key between curly brackets (${BUILD_SETTINGS_KEY}
) is a way to reference a build setting value.
In this case, our bundle name is set to the PRODUCT_NAME
key in the build setting.
So, we need to modify the PRODUCT_NAME
value in the build setting if we want to change the app name.
To do that.
- Select the "Build Settings" tab.
- Search for "product name". The key in the build setting is usually named after the key you see in the Info.plist, which is
PRODUCT_NAME
in this case. - Click on the arrow on the left of the "Product Name". You will see two nested rows with the key named after the Xcode build configuration,
Debug
, andRelease
. - Double-click on the value to change it. In this case, I change the app name for debug configuration to "Sarunw-Sample Debug".

That's all you need to do to change the app name based on the build configuration.
You can easily support sarunw.com by checking out this sponsor.
Sponsor sarunw.com and reach thousands of iOS developers.
Setting a custom value
If you need to define a new Info.plist key and new Build configuration value, you can also do that.
In this example, I will create a new Info.plist key for an imaginary API Key, SARUNW_API_KEY
.
Create a new Info.plist key
To create a new Info.plist key.
- Open the Info tab.
- Hover on the last row and click on the plus button (+).
- New row will appear. Name it whatever you want. In this case, I named it
SARUNW_API_KEY
.

Create a new Info.plist key.
- Set the value by double-clicking on the value column. I want to use different values based on the build setting, so I will put a reference to a key in the build setting. In this case, I put it under the same name,
${SARUNW_API_KEY}
.

Set value to value in the build setting.
At this point, we got new Info.plist key with the value point to the SARUNW_API_KEY
key in the build setting.
The last thing we need to do is create this key in the build setting.
Create a user-defined setting
To create a new key in the build setting.
- Open the Build Settings tab.
- Click on the plus button (+) at the upper left, then select "Add User-Defined Setting". Enter the name of the new key. In this case, I named it
SARUNW_API_KEY
.

Add User-Defined Setting.
- Expand the new setting, and set the value based on the build configuration.

With this setting, you can have different SARUNW_API_KEY
based on debug and release configuration.
You can test it by reading the value from the Info.plist file.
print(Bundle.main.object(forInfoDictionaryKey: "SARUNW_API_KEY"))
// Debug configuration
// DEBUG-API-KEY
// Release configuration
// RELEASE-API-KEY
Recommend
-
10
Xcode Build Configuration Files Written by
-
11
How to Add NSLocationAlwaysUsageDescription Key to Info.plist File in Your iOS AppHow to Add NSLocationAlwaysUsageDescription Key to Info.plist File in Your iOS App by@kapilgorve
-
13
属性表文件(Plist)是一种文件形式,通常用于储存用户设置,也可以用于存储捆绑的信息,该功能在旧式的Mac OS中是由资源分支提供的。由于Plist中存储的数据是抽象的,其采用的文件格式可以不止一种。 macOS看起来非常有趣,尤其是...
-
12
How to read App Name, Version, and Build Number from Info.plist 17 May 2021 ⋅ 4 min read ⋅ Swift
-
7
When you create a new SwiftUI project with Xcode 13 you may notice it doesn’t have an Info.plist file. What’s going on? I wrote this post based on Xcode 13 beta 3. I’ll update it if I see changes in future beta releases
-
4
Apple Says Third-Party Apps Can Take Full Advantage of ProMotion With Plist Entry, Core Animation Bug Fix Coming ...
-
7
New issue macos path fix in launchd plist #7288
-
6
iPhone Plist Tutorial Posted on February 19, 2009 Update 03/03/12: Please don't listen to this. Using JSON is highly preferred over...
-
14
how to embedded a Info.plist into arbitrary binaries One of the changes introduced by Mountain Lion was the removal of the old procmod convention for applications that want to access the task port of a process (aka fo...
-
11
由 王巍 (onevcat) 发布于 11 小时前2022-10-14T11:00:00+09:00TL;DR当前,在 Xcode 中使用 Swift Package Manager 的包时,SPM 在编译 package 时将参照 Build Configuration 的名字,
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK