Published:

Tagged: Swift Xcode

Using old versions of Swift in Xcode

The problem we’re trying to solve

Apple released new versions of iOS, watchOS, tvOS & MacOS yesterday, and with it came a new version of Xcode, 8.3, that only includes Swift 3.1 — the latest and greatest of Swift. This becomes a problem if you’re using a 3rd party libraries in binary form.

Example: As I’m writing this, the current version of Realm’s “Mobile Database” is 2.4.4 which comes with binaries for Swift 3.0, 3.0.1 & 3.0.2, making it unusable with the default Swift toolchain for Xcode 8.3.

The Solution: multiple Swift toolchains

Apples makes previous Swift toolchains available for download here: https://swift.org/download/#releases.

Example: Swift 3.0.2 is available as part of Xcode 8.2 but also as a separate download (see the image below). Click on the (Toolchain) link to start the download.

Old Swift in Xcode - Swift 3.0.2

Each toolchain is available as a .pkg archive that can be downloaded & installed— it will require system admin access to install.

Old Swift in Xcode - Toolchain Install

Once that is in place and Xcode is restarted, a new entry will appear in the Xcode menu where the active toolchain can be chosen at will:

Old Swift in Xcode - Xcode Toolchains

A new tab item will also appear under Settings > Components: Toolchains. You can use this to pick the active toolchain or, verify or delete installed toolchains.

Old Swift in Xcode - Xcode Components Toolchains

NB: The “default” toolchain that came with Xcode can’t be removed. Also, deleting all the extra toolchains will cause the Toolchains tab item, as well as the menu entry, to dissapear.

That’s all folks!