I recently ran into an issue in Xcode where I downloaded a sample repository for a project. Then I followed the instructions listed in the repository’s README file. Come to find out that a library was built with a prior version of Swift than the version installed with my version of Xcode. That’s really frustrating considering that maintaining multiple versions of Xcode can be quite a pain. In this article, I am going to show you how you can work with multiple Swift versions in XCode.
The good news is, that we can use something called Xcode toolchains. You can download a prior version of Swift, and then install it on macOS as an administrator. Then after restarting Xcode, you will then have a new menu option to switch toolchains.
First, visit https://swift.org/download/#releases and choose the version of Swift you want, click the
Toolchain link to download the package, then install it on macOS (OSX). After installation is complete, you can open Xcode, restarting first if need be, and then clicking on the Xcode menu option, and there should now be a Toolchains menu option as seen in the screenshot below.
After selecting your desired toolchain, you can now build those projects whose dependent libraries were built using another version of Swift! Now you’re able to switch between multiple Swift versions in XCode!
You can also find the different toolchains under
Xcode > Preferences > Components if you wish to remove it. Hope this helps someone like it helped me!