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

2

8

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?

Musgrave answered 25/5, 2016 at 3:40 Comment(0)
A
6

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

Asp answered 25/5, 2016 at 4:55 Comment(1)
how do i get a particular flag? like, i have added DEBUG flag and now i wanna check that in script execution.Stowell
Z
10

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
Zea answered 10/4, 2019 at 10:42 Comment(0)
A
6

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

Asp answered 25/5, 2016 at 4:55 Comment(1)
how do i get a particular flag? like, i have added DEBUG flag and now i wanna check that in script execution.Stowell

© 2022 - 2024 — McMap. All rights reserved.