Xcode variables

XcodeVariablesBuild ProcessBuild Automation

Xcode Problem Overview


In Xcode, I know that you can get variables such as PROJECT_DIR to use in some situations, such as a run script build phase. I am wondering if it's possible to get the build type (i.e., Release or Debug). Any ideas?

Xcode Solutions


Solution 1 - Xcode

The best source is probably Apple's official documentation. The specific variable you are looking for is CONFIGURATION.

Solution 2 - Xcode

Here's a list of the environment variables. I think you might want CURRENT_VARIANT. See also BUILD_VARIANTS.

Solution 3 - Xcode

They're not all documented. For example, you won't find ARCHIVE_PATH, MARKETING_VERSION (the version string set in Xcode) in Naaff's or smorgan's answer. These 2 are very common pieces of information someone would need! Here's a list of all of them I got: https://gist.github.com/ben-xD/c063b0ca2c33684de1eb379bb9d6405d

How I got them

I found the best way was to print them using set, I just wrote this including a method to list all the environment variables available.

Add this to your run script (either Archive post run script, or your build phases run script, etc.):

#!/bin/sh
exec > ${PROJECT_DIR}/environment_variables.log 2>&1
set

Look in environment_variables.log and you'll see them all.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAllynView Question on Stackoverflow
Solution 1 - XcodesmorganView Answer on Stackoverflow
Solution 2 - XcodeNaaffView Answer on Stackoverflow
Solution 3 - XcodeBen ButterworthView Answer on Stackoverflow