How to read environment variables in info.plist?
Asked Answered
C

3

12

I am setting a variable in the terminal

export VAR=1.0.0

And I have to read it from ~/.bash_profile into the info.plist like for example:

<key>CFBundleShortVersionString</key>
<string>VAR</string>

So like this I can do automated builds. Is there a way how to read the variables?

Cauchy answered 20/4, 2017 at 7:40 Comment(2)
Maybe will help you #9530575Plosive
Right now I am trying to read a ~/.bash_profile variable and add it into info.plists. Not sure with the abouve example will work but ill try more ways. Thank you for help!Cauchy
T
6

In the info.plist you reference the variable:

<key>CFBundleShortVersionString</key>
<string>$(VAR)</string>

Then when you build the project from the terminal you inject the value for the VAR:

xcodebuild build VAR=123 -project myProject.xcodeproj -target myTarget -sdk iphonesimulator

Or if the variable in set in the environment:

xcodebuild build VAR=${VAR} -project myProject.xcodeproj -target myTarget -sdk iphonesimulator
Tollefson answered 26/6, 2021 at 22:50 Comment(0)
I
-2

Please refer this link on SO,

PLIST Variables

$(PRODUCT_BUNDLE_IDENTIFIER) and $(PRODUCT_NAME) comes from Build Settings.

And ${EXECUTABLE_NAME} is concatenation of:

$EXECUTABLE_PREFIX, $PRODUCT_NAME and $EXECUTABLE_SUFFIX.

Hope this will help you.

Investment answered 20/4, 2017 at 7:48 Comment(2)
I realised that I have not specified everything in my question so I have edited a bit. Maybe you know a way around.Cauchy
The question was about environment variables in the build environment and not about referring to other variables or values inside the info.plist.Whaler
R
-4

You can use bundle to access the Info.plist.

 let v = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
Rattlebrain answered 20/4, 2017 at 7:47 Comment(1)
Accessing the info.plist is not related to the question.Whaler

© 2022 - 2024 — McMap. All rights reserved.