Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 448
Dj S Avatar asked May 25 '16 03:05

Dj S


People also ask

How to integrate swiftlint with Xcode?

Integrate SwiftLint with Xcode In order to integrate SwiftLint with Xcode project target to get warnings and errors displayed in the Xcode IDE, you just need to add a new “Run Script Phase” with following script - If you don’t know how to add a “Run Script Phase” in your project target, here an image for your reference -

How to run custom build scripts in Xcode cloud?

When Xcode Cloud executes a new build, the custom build scripts are automatically detected and run at their designated time in the timeline. To create the ci_scripts directory, navigate to the Project Navigator in Xcode and Control-click your project, choose New Group to create the group and its corresponding directory, and name it ci_scripts.

How to manage build phase scripts in Xcode?

Use the following convention to manage you build phase scripts: There must be one shell script per build phase. For example, put all your build phase scripts in a directory named build-phases, e.g. build-phases/codecheck.sh, build-phases/codegen.sh, etc. In Xcode build phase UI instead of having an inline script, you have this now:

Why are my shell scripts not showing up in Xcode project?

The problem is that shell scripts ran in Xcode build phases do not source the user shell profile. Then run the build phase by building Xcode project. None of the messages from shell profiles will show up. The reason is that a shell ran from Xcode build phase is non-interactive shell.


1 Answers

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
like image 119
apparition47 Avatar answered Nov 09 '22 22:11

apparition47