Compiling in Swift takes ages and Xcode happily compiles everything every time one even looks at the source code funnily. Compiles with Swift typically take around 10 – 20 times as long as their equivalent Obj-C counterparts and we have seen much worse. Projects for iOS tend to fare better than their macOS cousins even with the overhead of launching a simulator, but things really slow down dramatically when multiple languages are used in the same project. There are several reasons for this and some measures that can be taken to optimize things. In this brief post we are taking a look at the new -enable-bridging-pch option that Apple made available in Xcode 8.3 with Swift 3.1.
PCH stands for pre-compiled headers which is fairly self-explanatory. Of course Swift doesn’t have headers, but there are very few non-trivial pure Swift projects out there. Most everything else contains generous helpings of Obj-C. In these cases there are not only the Obj-C headers, but also the so-called bridging headers that the Swift compiler needs. Enter the -enable-bridging-pch compiler option.
As seen this option is set in the “Other Swift Flags” group in build settings. It has no effect in whole-module-optimization builds and only makes sense in a mix-and-match situation. The Swift Team reports reduced build times of up to 30%. So – give it a try.