9

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?

NinetyHH
  • 1,494
  • 4
  • 19
  • 32
  • Maybe will help you http://stackoverflow.com/questions/9530075/ios-access-app-info-plist-variables-in-code – Roman Podymov Apr 20 '17 at 07:45
  • 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! – NinetyHH Apr 20 '17 at 07:56

3 Answers3

4

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
Christos Koninis
  • 1,499
  • 1
  • 15
  • 28
-1

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.

Community
  • 1
  • 1
KAR
  • 3,303
  • 3
  • 27
  • 50
  • I realised that I have not specified everything in my question so I have edited a bit. Maybe you know a way around. – NinetyHH Apr 20 '17 at 08:05
  • 4
    The question was about environment variables in the build environment and not about referring to other variables or values inside the `info.plist`. – p13n Sep 28 '18 at 13:44
-3

You can use bundle to access the Info.plist.

 let v = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
Rahul
  • 2,056
  • 1
  • 21
  • 37