xcode 如何选择 Swift 编译器版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36213067/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:40:01  来源:igfitidea点击:

How can I choose Swift compiler version

iosxcodeswift

提问by Lumialxk

I'm using Xcode 7.3 but my project is in Swift 2.1. I don't want to update my codes right now. So how can I choose or download older version of Swift compiler? Many thanks in advance!

我使用的是 Xcode 7.3,但我的项目是 Swift 2.1。我现在不想更新我的代码。那么如何选择或下载旧版本的 Swift 编译器呢?提前谢谢了!

采纳答案by rob mayoff

Originally I posted this is a comment, but I should have just posted it as an answer:

最初我发布这是一条评论,但我应该将其发布为答案:

If you're writing an app for the App Store, you can only use a release (non-beta) version of Xcode (see “Submitting Apps to the App Store using Xcode”)and the toolchain supplied with that version of Xcode (see “Using Downloads / Apple Platforms”). So you can either use Xcode 7.2 and continue using Swift 2.1, or you can use Xcode 7.3 and update your code to Swift 2.2.

如果您正在为 App Store 编写应用程序,则只能使用 Xcode 的发布(非测试版)版本(请参阅“使用 Xcode 将应用程序提交到 App Store”)和该版本 Xcode 提供的工具链(请参阅“使用下载/Apple 平台”)。因此,您可以使用 Xcode 7.2 并继续使用 Swift 2.1,也可以使用 Xcode 7.3 并将代码更新为 Swift 2.2。

You can have multiple versions of Xcode installed.You can keep Xcode 7.2 installed and use it for your non-updated Swift 2.1 projects, and use Xcode 7.3 on new projects. Note that you'll have to manually open each project in the appropriate version of Xcode.You can download old versions of Xcode here.

您可以安装多个版本的 Xcode。您可以保持 Xcode 7.2 的安装并将其用于未更新的 Swift 2.1 项目,并在新项目中使用 Xcode 7.3。请注意,您必须在相应版本的 Xcode 中手动打开每个项目。您可以在此处下载旧版本的 Xcode。

If you're not going to put your app in the App Store, then maybeyou could extract the Swift 2.1 toolchain from the Xcode 7.2 bundle and turn it into a .xctoolchainfor use with Xcode 7.3, but you're really in unexplored, unsupported territory if you go that route.

如果你不打算把你的应用程序在App Store,那么也许你可以从Xcode的7.2束提取雨燕2.1工具链,使之成为一个.xctoolchain在Xcode 7.3中使用,但其实你在未知,不支持境内如果你走那条路。

回答by Nikolay Shubenkov

The following example is tested on Xcode 8.3 with swift 3.1

以下示例在 Xcode 8.3 和 swift 3.1 上测试

If you are using Xcode 8 you can download toolchains with needed Swift versions

如果您使用的是 Xcode 8,则可以下载具有所需 Swift 版本的工具链

1) Open this link: https://swift.org/download/#releases

1) 打开这个链接:https: //swift.org/download/#releases

2) Download Toolchain with swift version that you need. For example I have 3.1 version of swift and downloaded swift 3.0.2

2) 下载您需要的带有 swift 版本的 Toolchain。例如我有 3.1 版本的 swift 并下载了 swift 3.0.2

enter image description here

在此处输入图片说明

3) Open .pkg file and install it.

3) 打开.pkg 文件并安装它。

enter image description here

在此处输入图片说明

4) Open Xcode and select in menu:

4)打开Xcode并在菜单中选择:

Xcode -> Toolchains -> Select Swift Version you need.

Xcode -> Toolchains -> 选择你需要的 Swift 版本。

That is all folks

就这些了

enter image description here

在此处输入图片说明

回答by Guy Daher

Xcode 9 - Xcode 10

Xcode 9 - Xcode 10

Select your target, then in your Build Settings, search for "swift language" and then you will find Swift Language Version.

选择您的目标,然后在您的 中Build Settings,搜索“swift language”,然后您会找到Swift Language Version.

enter image description here

在此处输入图片说明

回答by allenh

If you're following the answers involving a .xctoolchaincombined with Xcode 9beta you'll encounter an error similar to this: <unknown>:0: error: unknown argument: '-index-store-path' Command /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchai??n/usr/bin/swiftc failed with exit code 1

如果你在涉及答案一个.xctoolchain结合的Xcode 9测试版,你会遇到类似这样的错误: <unknown>:0: error: unknown argument: '-index-store-path' Command /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchai??n/usr/bin/swiftc failed with exit code 1

The reason is that Apple has added a new feature/argument, which hasn't made its way to open source Swift yet. You can get around this issue by launching Xcode from the command line with the feature disabled like this: /path/to/Xcode-beta.app/Contents/MacOS/Xcode -IDEIndexEnableBoltIndex NO

原因是 Apple 添加了一项新功能/参数,但尚未开源 Swift。您可以通过从命令行启动 Xcode 并禁用该功能来解决此问题,如下所示: /path/to/Xcode-beta.app/Contents/MacOS/Xcode -IDEIndexEnableBoltIndex NO

Thanks to the Swift team

感谢Swift 团队