Xcode 10’s build system and Code Generation (R.swift)

Pete Smith
Sep 5, 2018 · 2 min read

Xcode 10 includes a new build system, enabled by default, which improves build performance. This is a very welcome improvement.

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

Zendesk Engineering

Engineering @ Zendesk

Pete Smith

Written by

Team Lead @zendesk

Zendesk Engineering

Engineering @ Zendesk

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade