Mark Norgren
Mark Norgren

Reputation: 2014

How can I read a custom key's value in Info.plist and use it in Xcode's build settings?

I am attempting to read a custom info.plist key's value into a User Defined Build Setting.

The 'APP_VERSION' is a macro defined in my INFOPLIST_PREPROCESSOR_DEFINITIONS file.

What I am trying to accomplish is getting macro definitions from my INFOPLIST_PREPROCESSOR_DEFINITIONS file into build settings based on different configurations.

I am going about this the wrong way? Or am I just missing something.

info.plist custom key

build settings

Upvotes: 5

Views: 4959

Answers (1)

Dave Wood
Dave Wood

Reputation: 13333

You can use the PlistBuddy command in a 'Run Script Build Phase' to read and/or write values in your info.plist file.

To read:

/usr/libexec/PlistBuddy -c 'print PRX_APP_VERSION' Info.plist

To write:

/usr/libexec/PlistBuddy -c "Set :BUNDLE_DISPLAY_NAME NEW_VALUE" Info.plist

So in your Run Script Build Phase, read the value (or values) you want, store them into variables using standard shell scripting, modify as required, then write the values back to the new keys etc.

Upvotes: 2

Related Questions