4

I am running a pre-build script using scheme. My script has enabled option to provide build settings from target that is being built. This script also gets executed when project is built for SwiftUI Previews. I need to know inside this script if the build that is being run is regular one or for previews. Is there a way to do that and how?

I tried running export in the script in both scenarios but it seems that all environment variables are the same in both cases.

1
  • I know there is a flag XCODE_RUNNING_FOR_PREVIEWS in process info to check while the app is running but I need something similar that is available during build Commented Jan 21, 2022 at 14:00

1 Answer 1

6

It is possible to check ENABLE_PREVIEWS environment variable in scripts.

It is YES for [Build for Previews TARGET]:

demo1

and NO for [Build for TARGET]:

demo2

Tested with Xcode 13.2 / iOS 15.2

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately it works only for build (the one in build phases), not for pre-build scripts (those in schemes). I need my script to be ran in the pre-build section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.