Xcode 变量

在 Xcode 中,我知道可以在某些情况下使用 PROJECT_DIR等变量,例如运行脚本构建阶段。我想知道是否有可能获得构建类型(例如,放手调试)。有什么想法吗?

133443 次浏览

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

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

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.