Xcode Build Setting Transformations

August 8, 2015

Xcode supports the ability to substitute the value of build settings using the $(BUILD_SETTING_NAME) or ${BUILD_SETTING_NAME} syntax in a number of places including Info.plists, other build setting values, and .xcconfig files. In these substitutions it’s also possible to add operators that transform the value in various ways. You may have seen one of these in the Info.plist included in project templates:

com.company.$(PRODUCT_NAME:rfc1034identifier)

This results in the value of the PRODUCT_NAME build setting being transformed into a representation suitable for use in the reverse DNS format used by CFBundleIdentifier. So if PRODUCT_NAME is “Whatever App” the resulting string is “com.company.Whatever-App”.

These transformations can be quite useful but don’t appear to be documented, so here’s the list of available operators and what they do:

OperatorReturns
identifierA C identifier representation suitable for use in source code.
c99extidentifierLike identifier, but with support for extended characters allowed by C99. Added in Xcode 6.
rfc1034identifierA representation suitable for use in a DNS name.
quoteA representation suitable for use as a shell argument.
lowerA lowercase representation.
upperAn uppercase representation.
standardizepathThe equivalent of calling stringByStandardizingPath on the string.
baseThe base name of a path - the last path component with any extension removed.
dirThe directory portion of a path.
fileThe file portion of a path.
suffixThe extension of a path including the '.' divider.

Note that these operators can be chained, so you can do things like $(PRODUCT_NAME:lower:rfc1034identifier) or $(CONFIGURATION:upper:identifier).