(I’m not apologizing for the clickbaity title since it actually works and it is a little weird…)
I’ve been working on improving Swift build times off and on for the past few weeks, and today I stumbled across the best possible improvement: a one-line change that cut our build times in half. I noticed in our build logs that all our files were being compiled twice and set off to investigate why. I eventually stumbled across this Stack Overflow post which led me to the solution: set Build Active Architectures Only to Yes for all non-release builds. Our app actually has several configurations that we use (not just Release and Debug like most projects), so I set this to Yes for all the configurations we use for development. Here’s a screen shot of what this looks like in a standard app:
And here are the step by step instructions to make this happen:
- Select your project file in the Project navigator
- Select your project name in the left side of the editor
- Select the Build Settings tab
- Under the Architectures heading, find the Build Active Architecture Only setting and flip it to Yes for any configurations you use only for development.
Note that you’ll need to have it set to No for any App Store builds you do, so I’d recommend setting it to Yes only for the Debug configuration and spending most of your development time with that configuration selected.
Build times for our app on my machine went down from about 90 seconds to 45 every time I run the app in the simulator or on my device. I’m ecstatic.