Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What versions of Swift are supported by what versions of Xcode?

I develop apps in Swift for a living. I enjoy the language and follow it as closely as I can. Yet, still, certain facts slip through, whether by me being blindsided, or by Apple being very quiet about them.

Today, I discovered that Swift 3.3 and 3.4 exist. I was under the assumption that 3.2 was the last version of 3, for use in migrating to 4, 4.2, and 5. This misconception is mostly due to the fact that Swift.org, the official Git repo, and Xcode Release Notes don't mention them at all.

So, I assume these are also transitional, but I've no idea what IDE or compiler they appear in, or what caveats they come with. Below is a table which sums up my knowledge:

The below table is outdated, provided for context so the question makes sense. I've posted an updated version of this table in an answer below.

A complex table with many versions of Swift and Xcode as the axes, and the support versions as the content

What goes in the purple spaces? Specifically for the 3.3 and 3.4 rows, but if you know the other ones, that would help too!

Authoritative sources would also be awesome.


Possible answers to the primary question are as follows:

  1. Swift 3.3 was only in Xcode 9.3 beta and never became public; Swift 3.4 was only in Xcode 9.3 - 9.4
  2. Swift 3.3 was only supported in Xcode 9.3; Swift 3.4 was supported in Xcode 9.3.1 and 9.4
  3. Swift 3.3 was supported in Xcode 9.3 and 9.3.1; Swift 3.4 was only supported in Xcode 9.4
  4. Swift 3.3 was supported in Xcode versions 9.3 though 9.4; Swift 3.4 was only supported in an Xcode 10 beta.

I don't think there's another possibility. Do let me know if I'm off-base, though.

like image 555
Ky. Avatar asked Jul 17 '18 16:07

Ky.


People also ask

What version of Swift is in Xcode 12?

Xcode 12 contains the next Swift update bundled, version 5.3. The more the Swift language advances, the more features we all get, resulting to better, safer, clearer and more robust code. Once again Swift brings improvements that most of them will be proved useful to all developers.

How do I specify Swift version in Xcode?

It can be done using Xcode, Go to Xcode->Preferences->Components-> Toolchains section and Select the Swift. 3.1. 1 snapshot, this will set the new Swift version for the local Xcode. You may need to restart Xcode.

Which Xcode supports swift3?

Swift 3.3 was only supported in Xcode 9.3; Swift 3.4 was supported in Xcode 9.3. 1 and 9.4. Swift 3.3 was supported in Xcode 9.3 and 9.3.


2 Answers

Since I've been gathering data and doing tests, I'll post my results as an updated chart in this answer:

A chart depicting the different versions of Swift as compared to their respective versions of Xcode. Last updated 2020-02-25

Awhile ago, I found out that newer versions of Xcode do not, in fact, support migrating from all older versions of Swift. I did explicitly test that Xcodes 10.2 through 11 don't support Swift 3.x and earlier, so I colored those white. I've not yet had time to test Xcode 8.3 through 10.1, but I suspect they will migrate 3.x but not 2.x or earlier; that's why there's a big "Unknown" block at the top.


Sources

  • Manual testing with this test code: https://github.com/BenLeggiero/Swift-Version-Checker
  • Xcode Release Notes
  • Swift Release Notes
like image 96
Ky. Avatar answered Sep 22 '22 03:09

Ky.


This isn't a complete answer to fill all the unknown spaces in your diagram, but perhaps I can fill in some thing helpful regardless...

Swift 3.x?

When Swift 4 development got underway (and first formally announced at WWDC17), the version number of the compiler forked from that of the language. (It's much like how, say, the ANSI C standard has different versioning from the clang and GCC compilers.)

The language version number tracks source compatibility — of the language definition itself, of the standard library, and of the way that Apple platform SDKs appear in Swift. If you have "Swift 3" code, you should be able to compile it with version 3 of the Swift compiler, or any later version of the compiler when using the -swift-version 3 option.

But "Swift 3" — the language version — isn't staying fixed, either. As Swift continues to evolve, changes to the language, standard library, and SDKs that are purely additive become available to Swift 3. So, if you have a Swift 3 codebase and start working with a newer compiler, you can choose whether to convert everything to Swift 4, start using the new compiler features, or retain compatibility with older Swift 3 compilers.

This means there's a mapping of compiler versions to possible language-compatibility versions:

  • Swift language 3.2 is "Swift 3 mode" for the Swift compiler 4.0
  • Swift language 3.3 is "Swift 3 mode" for the Swift compiler 4.1
  • Swift language 3.4 is "Swift 3 mode" for the Swift compiler 4.2

There is not yet a Swift 5 (language or compiler) release, but when that happens, it'll likely allow building in -swift-version 4 mode, creating a "Swift 4.3" language version. (Assuming future Swift 4.x releases don't take those numbers first.)

I'm not aware of a single source for this answer, but you can put it together from:

  • Version Compatibility in The Swift Programming Language book
  • SE-212 Compiler Version Directive
  • WWDC17 and WWDC18 What's New in Swift talks
  • downloading various beta, current, and past Xcode versions

Version History

Some minor corrections to parts of your diagram that are further in the past:

  • Xcode 8 included two separate versions of the compiler, rather than one compiler with a -swift-version switch. Xcode 8.3 stopped including the Swift 2.3 compiler, leaving Swift 3.1 as the only supported Swift language in that version.

  • Xcode 7 / Swift 2 never supported compiling Swift 1.x code, only migrating it. Xcode 7.2 and beyond, up to the current Xcode 10 beta, still include the "Convert to Current Swift Syntax" migrator, which in theory supports migrating from any older version of Swift.

  • Xcode 6.0 through 6.2.x supported running Xcode on OS X Mavericks (10.9). Xcode 6.3 was the first to require OS X Yosemite (10.10).

Additional sources: old Xcode downloads.

Discouraged?

I'm not sure how well this label applies...

  • During the time when Xcode 8.x included the Swift 2.3 compiler, it was fully supported for building apps and submitting to the App Store. You could say that it was nonetheless "discouraged" at that time, though, in that Apple said both that it wouldn't stick around and that Swift 3.0 would be the first language version that later compilers are backward source compatible to.

  • Swift 3.2 is/was fully supported in Xcode 9 — unlike Swift 2.3 -> 3.0, there's no "get off this version before we take it away" messaging from Apple or the Swift open source project. Swift language versions 3.2, 3.3, and 3.4 are there explicitly for the reason of allowing developers to maintain "Swift 3" codebases while gaining the benefits of newer compiler and IDE releases.

like image 23
rickster Avatar answered Sep 25 '22 03:09

rickster