Xcode 10’s build system and Code Generation (R.swift)
R.swift is an open source library which makes it both easier and type-safe to use resources such as images, fonts, and segues. It’s a really cool library, and we have used it successfully at Zendesk for quite a while now.
However…
The Problem
When building a project which uses R.swift with Xcode 10, the build will fail with the following error:
error: Build input file cannot be found: /LOCATION/R.generated.swift
Why This Happens
R.swift is integrated into projects using an Xcode build script phase. This phase generates a Swift file, R.generated.swift, which is compiled when the project is built.
The build fails because Xcode 10, with its new parallelizing build system, is trying to locate the R.generated.swift file before it has been created.
The Solution
Xcode 10 allows us to specify an output file for a build script phase. We can add our R.generated.swift file as an output file as follows:
Adding our R.generated.swift file as an output file in our Xcode build script phase
This results in a successful build. Awesome! 🎉
Additional
When we encountered this initially, we opened a bug with R.swift. However, as shown above, the issue is due to changes in Xcode’s build system.
That’s it! 📱🚀👍🏽
Also available on petethedeveloper.com