Xcode Transformers – Settings In Disguise

We’re great fans of .xcconfig files and other textua Xcode build process manipulations around here, and here’s some handy undocumented feature tips for you:

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…

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

Be sure to bookmark that for next time you’ve got some manipulating setup to do!

h/t: Michael Tsai!

UPDATES:

Sam Marshall writes lots of Xcode-related goodies, check out particularly

The Unofficial Guide to xcconfig files; Managing Xcode; Using Xcode Targets

Convenient Build Settings

Stencil Xcode Plugin “is an Xcode plugin that provides the ability to create custom file templates and use them in your project to create new files groups.”

SwiftLint: “A tool to enforce Swift style and conventions.”

Setting up SwiftLint on Travis CI

“Watch Your Language!”: The Road to Cleaner Code with SwiftLint

SwiftLint Doing Its Best To Ease Conflict

Using SwiftLint and Danger for Swift Best Practices

Xcode Search: the Hidden Gems

Change your API endpoint/environment using Xcode Configurations in Swift

Alex | August 16, 2015

Leave a Reply