Reputation: 757
I want to use some custom constants in info.plist file to use it globally e.g
<key>FacebookAppID</key>
<string>$(my_custom_constant)</string>
Upvotes: 3
Views: 6426
Reputation: 1946
Set your custom variable in info.plist as shown below. I have taken "HockeyAppID" as example here.
Next, Add a variable in Build Settings under "User-Defined" for Debug and Release configuration in your case as shown below. Here, I have my own four different configurations.
As you know, different configuration values will be loaded at runtime based on the settings in scheme. In order to access HockeyAppId for Debug / Release configuration from info.plist, do the following.
enum InfoPlistKey {
static let hockeyappID = "HockeyAppID"
}
struct AppSettings {
private static var infoDict: [String: Any] {
if let dict = Bundle.main.infoDictionary {
return dict
} else {
fatalError("Info Plist file not found")
}
}
static let hockeyAppID = infoDict[InfoPlistKey.hockeyappID] as! String
}
Now, you can access HockeyAppId value from Info.plist as ,
let identifier = AppSettings.hockeyAppID
Please let me know in case of any issues.
Upvotes: 6
Reputation: 3937
You can create the variable by adding it as a "User-Defined Setting" to your target, in Build Settings. You can then set the variable value to different things for each of your build configurations.
Please see attached screenshot. You can ignore my Beta Prod and Beta Test configurations, as they probably don't apply to your situation.
Upvotes: 3