1

I’m starting to learn Swift, and have tried the Swift shell. I notice that it is Apple Swift version 5.1.3 . I though it was up to 5.2 by now.

How do I get the latest version of Swift on my MacOS? Is that affected by the XCode version?

I am running MacOS Catalina 10.15.6 and XCode 11.7.

1

Latest Swift comes with Xcode 11.5 which should run on Catalina. So go to the app store and download the latest version of Xcode.

1
  • I have already updated to XCode 11.7. – Manngo Sep 3 '20 at 1:44
1

You can use swiftenv to easily manage your Swift verisions. You can get it from here.

5
  • Thanks for your suggestion. I have installed it and run swiftenv versions and find that it reporst 5.2.4 which looks better. However, when I run the swift shell, it still says Welcome to Apple Swift version 5.1.3. – Manngo Sep 3 '20 at 7:28
  • Have you selected the Swift 5.2? swiftenv local 5.2.4 – Mateusz Szlosek Sep 3 '20 at 7:41
  • Just tried it. I get .swift-version: Read-only file system – Manngo Sep 3 '20 at 7:46
  • Are you able to create any file in current directory? Try swiftenv global 5.2.4 – Mateusz Szlosek Sep 3 '20 at 8:50
  • OK, I was at the root directory for some reason. When I cd to ~/ the command works. However, the version I get when I just run swift (located in /usr/bin/swift) is still the old one. The tool did help me to discover that the current version is at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift. – Manngo Sep 4 '20 at 1:02
1

https://swift.org/download/#releases

  • Download Xcode 11.5 and the swift toolchain from the above link.

  • Install the toolchain which is in the form of .pkg and will install the toolchain in /Library/Developer/Toolchains. However, if you manually build a toolchain, you can also instal it to ~/Library/Developer/Toolchains.

  • Open Xcode app menu > "Toolchains" options will appear and select the new toolchain.

For console use, run export TOOLCHAIN=swift. This will remain the same for that complier window. If you need it permanently add that line to your bash/zsh profile file and reopen Terminal.

If you built the toolchain manually, prepend the path to swift executable to the PATH variable.

https://swift.org/getting-started/#installing-swift

https://github.com/apple/swift#building-swift

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .