Allyn
Allyn

Reputation: 20441

Xcode variables

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?

Upvotes: 114

Views: 141998

Answers (3)

Ben Butterworth
Ben Butterworth

Reputation: 28572

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.

Upvotes: 9

smorgan
smorgan

Reputation: 21579

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

Upvotes: 162

Naaff
Naaff

Reputation: 9333

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

Upvotes: 25

Related Questions