39

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.

Rengers
  • 14,911
  • 1
  • 36
  • 54
Ky -
  • 30,724
  • 51
  • 192
  • 308
  • Migrated from [SoftwareEngineering.SE](https://softwareengineering.stackexchange.com/q/375347/153904) – Ky - Jul 17 '18 at 17:08
  • 5
    Your chart is delightful, but I don't understand why you need to _ask_ about this. Surely the way to find out what version of Swift is included in a version of Xcode is to download that version of Xcode and see. – matt Jul 17 '18 at 17:15
  • For example, Xcode 10 beta 3 includes Swift 3.4. How do I know? By _looking_. You don't need someone else to tell you that; _you_ can look. – matt Jul 17 '18 at 17:20
  • the shift is not that big , actually if you can shift to swift 3.2 then it's not even needed to go through 3.3 && 3.4 , just run the app in swift 4 and then everything should be clear – Shehata Gamal Jul 17 '18 at 17:22
  • 7
    Worth noting that Swift 3.2, 3.3 & 3.4 are pseudo versions – they solely exist to represent the Swift 4.0, 4.1 and 4.2 compilers running in Swift 3 compatibility mode respectively. There's a handy table in https://github.com/apple/swift-evolution/blob/master/proposals/0212-compiler-version-directive.md that maps compiler to language version per compatibility mode (note that rows for 5.0 and 5.1 are no longer accurate as the version bumping ceased with the implementation of the proposal). – Hamish Jul 17 '18 at 17:29
  • Thank you for the advice, @matt. I'm also concerned about sub-versions. Xcode's build settings, for instance, don't differentiate between 4.0 and 4.0.1 and 4.0.2 and 4.0.3. They're all just 4.0 from the UI. Do you have a methodology that could extract it? I do have all the xibs laying around so that would be immensely helpful – Ky - Jul 17 '18 at 19:09
  • @Hamish Thanks for calling that out explicitly! I tried to note that on my chart by using italic version numbers, with text at the bottom indicating what that means. Maybe I'll find a clearer way :) – Ky - Jul 17 '18 at 19:11
  • 1
    "Do you have a methodology that could extract it?" Yes, I do. And so do you. For example: https://www.hackingwithswift.com/example-code/language/how-to-check-the-swift-version-at-compile-time It is not difficult to write a little code snippet that uses that to tell you what Swift version we were compiled under. – matt Jul 17 '18 at 19:14
  • @matt I started going down that road since you wrote that comment, but rapidly ran into the confusion of the compiler version. For Swift 4.2 and later, this is easily solved by the `#if compiler(>=x.x)` directive, but... I'm not sure it's feasible to create a complex enough set of directives to detect the compiler version for Swift < 4.2 – Ky - Jul 17 '18 at 20:55
  • I don't see why a complex set of directives is needed — just a _lot_ of directives, in series. It's simple and easy. You really don't want me to write out all the code for you: `#if swift(>=3.0) print("3.0") #endif #if swift(>=3.1) print("3.1") #endif` and so on. The last one that prints is the one that it is. – matt Jul 17 '18 at 21:06
  • @matt sorry to imply I wanted you to write it. I mean the _compiler_ version, separate from the _language_ version. See the commented-out section of the file I wrote: https://github.com/BenLeggiero/Swift-Version-Checker/blob/master/main.swift – Ky - Jul 17 '18 at 21:10
  • Sorry, Swift is a language, so I understood the question ("versions of Swift") to be about the language version. I used the technique I described to learn that "Swift 3" in Xcode 10 beta 3 means Swift 3.4, as I already told you. Looking at the chart, that seems to me to be just the sort of thing you want to know. – matt Jul 17 '18 at 21:21
  • 1
    The compiler version can be obtained from running `xcrun swift --version` (you can use `xcode-select` to select the the version of command-line tools, or change it from within Xcode's preferences under the "Locations" tab). – Hamish Jul 17 '18 at 21:23
  • 2
    Worth noting that Wikipedia has a table of Swift compiler versions for Xcode versions, which might be useful: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions – Hamish Jul 17 '18 at 21:26
  • Thank you, @Hamish! I used that table to help build my chart. I also used my own findings to improve that table! – Ky - Jul 17 '18 at 21:28
  • Xcode 8.3.2 on macOS 10.11 - Where did you find that information? It seems to me that the last Xcode version supported on macOS 10.11 is 8.2.1. Moreover, it seems that the whole Xcode 8.3 series requires Sierra – gog Oct 12 '18 at 10:16
  • @gog from [Apple's Xcode Release Notes](https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW4): "Xcode 8.3.3 requires a Mac running macOS 10.12 or later." – Ky - Oct 12 '18 at 15:44
  • 1
    @BenLeggiero I've tried installing Xcode 8.3.2 on macOS 10.11 but, after expanding the .xip archive, the Xcode icon was under a "PROHIBITED SIGN". Double-clicking on it spawned an error. Unfortunately, as time passes by, the Apple documentation is becoming less and less accurate and detailed. The doc only talks about the latest v8.x version, but doesn't mention which version is the last supported on macOS 10.11. The Xcode wikipedia page is more accurate than the Apple documentation now! – gog Oct 15 '18 at 09:43
  • 1
    [this answer](https://stackoverflow.com/a/10335943/6059640) is more accurate about which Xcode version can be run on each macOS release – gog Oct 17 '18 at 09:32

2 Answers2

73

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

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • @L.Butz I'm glad it helps you too! I'll keep it updated just because I have to know, myself :P – Ky - Aug 01 '19 at 21:24
  • @BenLeggiero can I still use swift 4.2 if I use Xcode 11 ? and can it be published to app store if using swift 4.2 in Xcode 11. really need your info, I am beginner and confused with this. Thank you very much sir ... – Alexa289 Sep 14 '19 at 09:23
  • @Alexa289 According to that chart above, yes Xcode 11 does support Swift 4.2. Be aware, though, that this isn't the same Swift 4.2 which was in Xcode 10.1; this is actually the backend of Swift 5, but with Swift 4.2 syntax. I recommend you just use Swift 5; it's not that different. As for the App Store, I'm no Apple review employee so I can't say for sure... but I'd bet money that you'll be fine – Ky - Sep 17 '19 at 04:05
  • So that's what "transitional" means? That this Swift version is available, but we can expect different results than the original language, since the backend changed? – ravemir Sep 19 '19 at 14:05
  • 1
    @ravemir Like I mentioned in my previous comment, those aren't the same Swift as the similarly- (or identically-) numbered ones which were in previous versions of Xcode; they are actually the backend of the newest Swift version which that version of Xcode supports, but with the older Swift syntax (e.g. Xcode 10.2 supports Swift 4.1.50, which is Swift 5.0.1 with Swift 4.1.x syntax). Because of this oddness, I recommend you just use the newest Swift version which that version of Xcode supports; it's not that different. – Ky - Sep 19 '19 at 15:23
  • 1
    Please accompany any downvotes with a comment explaining how I can provide better answers from now on – Ky - Oct 18 '19 at 18:20
  • 1
    Unfortunately I can't upvote twice but thank you for keeping this maintained. – matt Jan 23 '20 at 18:13
  • No problem, @matt! After all, it helps me personally so I might as well share what I'm already tracking – Ky - Jan 24 '20 at 21:41
  • Silly question @BenLeggiero: where did you find this info? It is SUPER useful, but I can't seem to find any good sources mentioning Swift 5.2.1 being compatible with Xcode 11.5 for example. Am I not looking in the right places? I feel like I'm going mad sometimes, trying to find this info. Why doesn't Apple keep track of a similar chart somewhere ‍♂️ – Kymer May 29 '20 at 05:25
  • @Kymer Thanks for reminding me! I've added sources to my question. Lots of this info isn't documented anywhere except this answer! I use this to test every version of Xcode individually, with all of its supported Swift versions: https://github.com/BenLeggiero/Swift-Version-Checker. For Ubuntu, I use my laptop, which is on 18.04, and VMs to test their support – Ky - May 29 '20 at 20:16
  • 1
    @Kymer aside from testing myself, I do also always look at [the Xcode release notes](https://developer.apple.com/documentation/xcode_release_notes) and [Swift release notes](https://swift.org/download/#snapshots) – Ky - May 29 '20 at 20:17
  • 1
    This will be the SO.com question that affected my work the least, but that I love the most. – benc Oct 05 '21 at 02:14
7

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 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.

rickster
  • 124,678
  • 26
  • 272
  • 326
  • This is amazing, thank you for the very thorough answer! I'll definitely be able to make my chart more accurate. Just a few questions: Primarily... what do I do in the purple area for Swifts 3.3-3.4 / Xcodes 9.3-9.4? Also, could Xcode 7.x migrate Swift 1.0 to 2.x, or just 1.2 to 2.x? – Ky - Jul 17 '18 at 20:07
  • 1
    AFAIK the migrator doesn't know for sure what language version your project currently uses — it just knows what syntax patterns are no longer current and how to fix them. (At least, this was certainly the case in Xcode 7. Since Swift 3 / Xcode 8 your project contains at least some "intended Swift version" info, but it's not clear there's enough there to help the migrator with everything it needs to.) – rickster Jul 17 '18 at 20:51
  • I've taken all your advice to heart and made [an updated chart in my answer](https://stackoverflow.com/a/52819598/3939277). Thank you so much! – Ky - Oct 15 '18 at 15:49
  • 1
    Since the chart I posted seems to be helping people very well, I'll mark it as the accepted answer (mostly for Googlers). Because your answer got me on-track to figuring it out, I'll give it a bounty – Ky - Nov 26 '19 at 05:11