Let's say you want to have a different behavior in your app depending on whether you build it in Xcode or you perform an Archive. And you want this behavior to be done at compile time. Note that the use of different configurations is not what is wanted.
Here is a solution using the
ACTION Xcode property build setting. This property is documented in the Xcode Build Setting Reference:
ACTION environment variable has 2 interesting values:
- build: when the app is built
- install: when the app is archived
Here is what you can do to identify the type of build (Build, Archive) at compile time in Xcode:
- In the
Preprocessor Macros(GCC_PREPROCESSOR_DEFINITIONS) in the Builds Settings of your project, add:
- In your precompiled prefix header for example, you can now create a define
#if XCODE_ACTION_install #define IS_ARCHIVE_BUILD 1 #else #define IS_ARCHIVE_BUILD 0 #endif
You can then use the define
IS_ARCHIVE_BUILD to have a different behavior at compile time. This solution works fine with Xcode 7.3.1 as well as Xcode 8.0b1. It hasn't been tested with other Xcode versions.