Define some properties in an xcconfig file and then use them in code

Hello, I would like to define some properties in an xcconfig file and then use them in code. If I got it right, I'm supposed to first define a variable in an xcconfig file, then add that variable to info.plist file and then retrieve it in code by:

Bundle.main.object(forInfoDictionaryKey: "KEY")

However, this way I was only able to retrieve strings. I haven't been able to retrieve a boolean or an integer. In the info.plist file, when I choose a variable type different than string, xcode doesn't let me set variable as $(VARIABLE_NAME). Is what I'm trying to do possible? Am I missing something?

Replies

But you could easily set an integer or Bool as a String, and restorre the Integer or Boolean value in your code, or is it an issue for you ?

Am I missing something?

I don’t think you’re missing anything. It seems that Xcode’s

Info.plist
variable substitution substitution support only works for string values. I think it’d be reasonable for you to file an enhancement request requesting that this restriction be lifted. Pleaes post your bug number, just for the record.

You can work around this as described by Claude31: Use a string value and then convert that to the actual type you need at runtime.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"