Dj S
Dj S

Reputation: 10262

How to use Swift Flags inside a Run Script Build Phase in Xcode?

I added "-D MYOWNFLAG" to Other Swift Flags in Build Settings of Xcode. Now, in my Run Script found in Build Phases, I want to check for the existence of the flag "MYOWNFLAG" and execute something (e.g. change Info.plist setting value) if it exists.

Is this possible? If yes, what is the best way to do this?

Upvotes: 8

Views: 2927

Answers (2)

apparition47
apparition47

Reputation: 481

Should be able to use wildcards in conjunction with the $OTHER_SWIFT_FLAGS env variable.

if [[ $OTHER_SWIFT_FLAGS == *"-D MYOWNFLAG"* ]]; then
  echo "execute something (e.g. change Info.plist setting value)"
fi

Upvotes: 11

Max Chuquimia
Max Chuquimia

Reputation: 7854

You can check all available environment variables by running printenv from within a runscript phase.

The Other Swift Flags can be printed by running:

echo $OTHER_SWIFT_FLAGS

from within your runscript phase

Upvotes: 6

Related Questions