什么版本的 Xcode 支持什么版本的 Swift?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51386748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What versions of Swift are supported by what versions of Xcode?
提问by Ben Leggiero
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.
我以 Swift 开发应用程序为生。我喜欢这门语言,并尽可能密切地遵循它。然而,某些事实仍然存在,无论是因为我被蒙蔽了双眼,还是因为 Apple 对它们非常沉默。
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 Notesdon't mention them at all.
今天,我发现 Swift 3.3 和 3.4 存在。我假设 3.2 是 3 的最后一个版本,用于迁移到4、4.2和 5。这种误解主要是由于Swift.org、官方 Git 存储库和Xcode 发行说明不根本不提他们。
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:
所以,我认为这些也是过渡性的,但我不知道它们出现在什么 IDE 或编译器中,或者它们带有什么警告。下表总结了我的知识:
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.
下表已过时,提供了上下文,因此问题是有道理的。我在下面的答案中发布了此表的更新版本。
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!
紫色空间里有什么?专门针对 3.3 和 3.4 行,但如果您知道其他行,那也会有帮助!
Authoritative sources would also be awesome.
权威来源也很棒。
Possible answers to the primary question are as follows:
主要问题的可能答案如下:
- 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
- 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.1; Swift 3.4 was only supported in Xcode 9.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.
- Swift 3.3 只在 Xcode 9.3 beta 中,从未公开;Swift 3.4 仅在 Xcode 9.3 - 9.4 中
- Swift 3.3 仅在 Xcode 9.3 中受支持;Xcode 9.3.1 和 9.4 支持 Swift 3.4
- Xcode 9.3 和 9.3.1 支持 Swift 3.3;Swift 3.4 仅在 Xcode 9.4 中受支持
- Xcode 9.3 至 9.4 版本支持 Swift 3.3;Swift 3.4 仅在 Xcode 10 测试版中受支持。
I don't thinkthere's another possibility. Do let me know if I'm off-base, though.
我不认为还有其他可能。不过,如果我不在基地,请告诉我。
回答by Ben Leggiero
Since I've been gathering data and doing tests, I'll post my results as an updated chart in this answer:
由于我一直在收集数据并进行测试,因此我将在此答案中以更新的图表形式发布我的结果:
Awhile ago, I found out that newer versions of Xcode do not, in fact, support migrating from allolder 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.
不久前,我发现新版本的 Xcode 实际上不支持从所有旧版本的 Swift迁移。我确实明确测试过 Xcodes 10.2 到 11 不支持 Swift 3.x 及更早版本,所以我将它们涂成白色。我还没有时间测试 Xcode 8.3 到 10.1,但我怀疑他们会迁移 3.x 而不是 2.x 或更早版本;这就是为什么顶部有一个很大的“未知”块的原因。
Sources
来源
- Manual testing with this test code: https://github.com/BenLeggiero/Swift-Version-Checker
- Xcode Release Notes
- Swift Release Notes
回答by rickster
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?
斯威夫特 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.)
当 Swift 4 开发开始时(并在 WWDC17 上首次正式宣布),编译器的版本号与语言的版本号分叉。(这很像 ANSI C 标准与 clang 和 GCC 编译器的版本不同。)
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.
语言版本号跟踪源兼容性——语言定义本身、标准库以及 Apple 平台 SDK 在 Swift 中的显示方式。如果您有“Swift 3”代码,则在使用该-swift-version 3
选项时,您应该能够使用 Swift 编译器的第 3 版或任何更高版本的编译器来编译它。
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.
但是“Swift 3”——语言版本——也不是固定不变的。随着 Swift 的不断发展,对语言、标准库和 SDK 所做的纯粹可添加的更改可用于 Swift 3。因此,如果您拥有 Swift 3 代码库并开始使用更新的编译器,您可以选择是否转换所有内容Swift 4,开始使用新的编译器功能,或保留与旧的 Swift 3 编译器的兼容性。
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
- Swift 语言 3.2 是 Swift 编译器 4.0 的“Swift 3 模式”
- Swift 语言 3.3 是 Swift 编译器 4.1 的“Swift 3 模式”
- Swift 语言 3.4 是 Swift 编译器 4.2 的“Swift 3 模式”
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.)
目前还没有 Swift 5(语言或编译器)版本,但是当发生这种情况时,它可能会允许构建-swift-version 4
模式,创建一个“Swift 4.3”语言版本。(假设未来的 Swift 4.x 版本不会首先采用这些数字。)
I'm not aware of a single source for this answer, but you can put it together from:
我不知道这个答案的单一来源,但你可以把它放在一起:
- Version Compatibilityin The Swift Programming Languagebook
- SE-212 Compiler Version Directive
- WWDC17and WWDC18What's New in Swift talks
- downloading various beta, current, and past Xcode versions
- 版本兼容性的雨燕编程语言的书
- SE-212 编译器版本指令
- WWDC17和WWDC18Swift 会谈中的新功能
- 下载各种测试版、当前和过去的 Xcode 版本
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).
Xcode 8 包含两个独立版本的编译器,而不是一个带有
-swift-version
开关的编译器。Xcode 8.3 停止包含 Swift 2.3 编译器,让 Swift 3.1 成为该版本中唯一支持的 Swift 语言。Xcode 7 / Swift 2 从不支持编译 Swift 1.x 代码,只支持迁移它。Xcode 7.2 及更高版本,直到当前的 Xcode 10 beta,仍然包含“Convert to Current Swift Syntax”迁移器,理论上支持从任何旧版本的 Swift 迁移。
Xcode 6.0 到 6.2.x 支持在 OS X Mavericks (10.9) 上运行 Xcode。Xcode 6.3 是第一个需要 OS X Yosemite (10.10) 的版本。
Additional sources: old Xcode downloads.
其他来源:旧的 Xcode 下载。
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.
在 Xcode 8.x 包含 Swift 2.3 编译器期间,它完全支持构建应用程序并提交到 App Store。不过,您可以说当时它仍然“令人沮丧”,因为 Apple 表示它不会继续存在,并且 Swift 3.0 将是后来的编译器向后兼容的第一个语言版本。
Xcode 9 完全支持 Swift 3.2 — 与 Swift 2.3 -> 3.0 不同,Apple 或 Swift 开源项目没有“在我们将其删除之前先离开这个版本”的消息。Swift 语言版本 3.2、3.3 和 3.4 明确存在的原因是允许开发人员维护“Swift 3”代码库,同时获得更新的编译器和 IDE 版本的好处。