Xcode Build Setting Transformations
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:
Operator | Returns |
---|---|
identifier | A C identifier representation suitable for use in source code. |
c99extidentifier | Like identifier , but with support for extended characters allowed by C99. Added in Xcode 6. |
rfc1034identifier | A representation suitable for use in a DNS name. |
quote | A representation suitable for use as a shell argument. |
lower | A lowercase representation. |
upper | An uppercase representation. |
standardizepath | The equivalent of calling stringByStandardizingPath on the string. |
base | The base name of a path - the last path component with any extension removed. |
dir | The directory portion of a path. |
file | The file portion of a path. |
suffix | The 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)
.