What “Output Files” in Xcode Build Phases is for

Exploring a hidden corner of Xcode Build Phases

Thongchai Kolyutsakul
SwiftBlade

--

CocoaPods auto generated Build Phase to check Manifest.lock

If you use CocoaPods, it will generate an .xcworkspace file with some additional target “Build Phases” to support its operations, e.g. Check Pods Manifest.lock. In them, there are these Input/Output Files properties.

I’m wondering why we need to declare these files. Shouldn’t Xcode be able to read or write these files as we use them in Build Phases scripts? It doesn’t make much sense to me.

Apple’s documentation has some information on this.

You don’t have to specify input and output files, but it’s highly recommended that you do. Xcode uses the set of input and output files to optimize build times, by running your script only when necessary. If you don’t specify input or output files, Xcode runs your script every time you build the target. For more information, see Improving the Speed of Incremental Builds.

Looking at the linked Improving the Speed of Incremental Builds, I found this:

You must still specify an input and output file to prevent Xcode from running the script every time, even if your script doesn’t actually require those files. For a script that requires no input, provide a file that never changes as the input file. For a script with no…

--

--

Thongchai Kolyutsakul
SwiftBlade

iOS developer since 2009. Working @Viki in Singapore. I write about iOS development, Swift language, and general software engineers tips.