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.

  • Easily preview Mermaid diagrams
  • Live update when editing in your preferred editor
  • Capture screenshots with customizable margins
  • Create PNG from the Terminal
  • Free download on the Mac App Store
MarkChart
Here is a solution using the ACTION Xcode property build setting. This property is documented in the Xcode Build Setting Reference:

ACTION

The 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:
XCODE_ACTION_${ACTION}=1
  • In your precompiled prefix header for example, you can now create a define IS_ARCHIVE_BUILD:
#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.