Xcode comes bundled with a version of Swift. You can refer to this list for the shipped versions. Sometimes, you won’t want to upgrade Swift for your project. So if you update Xcode, yet you need an older Swift version, this is the guide for you.
Previously, you can select the toolchain under Xcode > Preferences > Components > Toolchains, but it seems like as of 2022, this feature has been removed. UPDATE: After you have installed another toolchain, the options will appear.. Select in Xcode > Preferences > Components > Toolchains.
Check your swift
Firstly, know the version.
xcrun swift --version
swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-126.96.36.1993.62 clang-13188.8.131.52),
But where is the swift toolchain from?
xcrun -f swift
This is the default Xcode app if installed from Mac App Store.
Installing alternative swift toolchain
You can download another swift version (select Toolchain for Xcode), and install it.
Thereafter, you can find it installed in la
We need to know the identifier for the toolchain to use. To do so, you can run eg.
With the identifier, you can now specify the toolchain to use:
xcodebuild -toolchain org.swift.550202109201a xcrun -toolchain org.swift.550202109201a
Or export as an environment variable:
With that, you can check your swift version with
xcrun swift --version and
xcrun -f swift, and it should be the toolchain you have just specified.