在 Xcode 10.2 中使用 Swift 3 - 命令 /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc 失败,退出代码为 1

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

Using Swift 3 in Xcode 10.2 - Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

iosswiftxcode

提问by Radu Ursache

My goal is to get the new Xcode 10.2 compile and run our projects that are build using Swift 3 and 4.2 (some cocoapods too) and since Xcode 10.2 comes with Swift 5, an unsupported swift error came up when trying to run the projects out of the box (this is expected):

我的目标是让新的 Xcode 10.2 编译并运行我们使用 Swift 3 和 4.2(也有一些 cocoapods)构建的项目,并且由于 Xcode 10.2 带有 Swift 5,因此在尝试运行项目时出现了不受支持的 Swift 错误盒子(这是预期的):

enter image description here

enter image description here

The solution here is to use an older toolchain as stated on blogs like this, which i did.

这里的解决方案是使用像这样的博客上所述的旧工具链,我就是这样做的。

enter image description here

enter image description here

All good so far. However, after installing the Swift 3 toolchain from Swift.org, compiling the project will bring the following error:

到目前为止一切都很好。但是,从Swift.org安装 Swift 3 工具链后,编译项目会带来以下错误:

Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

命令 /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc 失败,退出代码 1

enter image description here

enter image description here

I already deleted Derived Data folder, cleanup pods (my podfile) and reinstalled them, restarted Xcode and Mac multiple times.

我已经删除了派生数据文件夹,清理了 pods(我的 podfile)并重新安装了它们,多次重新启动了 Xcode 和 Mac。

Running xcrun -f swiftand swift --versionwill indeed print the correct swift 3.0 toolchain

运行xcrun -f swift并且swift --version确实会打印正确的 swift 3.0 工具链

enter image description here

enter image description here

Yes, I know I could just stay with Xcode 10.1 and don't have these issues. Code migration to Swift 4 is also an option but we don't have the time at hand for now so I'm trying to workout this walkaround.

是的,我知道我可以继续使用 Xcode 10.1 而不会遇到这些问题。代码迁移到 Swift 4 也是一种选择,但我们现在手头没有时间,所以我正在尝试练习这个演练。

Please help me to resolve this issue, I'm completely stuck. Thanks in advance.

请帮我解决这个问题,我完全被卡住了。提前致谢。

回答by Vinay Kiran

Xcode10.2 Release Notes

Xcode10.2 发行说明

Swift 5 no longer supports the Swift 3 Package.swift tools-version. Packages still on the Swift 3 Package.swift tools-version should update to a newer tools-version. (41974124)

Swift 5 不再支持 Swift 3 Package.swift 工具版本。仍在 Swift 3 Package.swift 工具版本上的包应该更新到更新的工具版本。(41974124)

Swift 5.0

斯威夫特 5.0

Source Compatibility As with Swift 4.2, the vast majority of sources that built with the Swift 4.2 compiler should compile with the Swift 5.0 compiler.

However, the Swift 3 compatibility mode will not be supported in the Swift 5 compiler. Swift 4.2 is the last release of Swift to support Swift 3 mode. There are important changes to both the surface of the language and the interior of its implementation in the releases following Swift 3 that will be the basis of future (and lasting) source and binary stability.

源代码兼容性 与 Swift 4.2 一样,绝大多数使用 Swift 4.2 编译器构建的源代码都应该使用 Swift 5.0 编译器进行编译。

但是,Swift 5 编译器将不支持 Swift 3 兼容模式。Swift 4.2 是最后一个支持 Swift 3 模式的 Swift 版本。在 Swift 3 之后的版本中,语言的表面和内部实现都有重要的变化,这将成为未来(和持久)源代码和二进制稳定性的基础。

回答by Eric

Using Swift 4.2.1toolchain work for me.

使用Swift 4.2.1工具链对我有用。

But https://swift.org/download/#using-downloadstips:

但是https://swift.org/download/#using-downloads提示:

To submit to the App Store you must build your app using the version of Swift that comes included within Xcode.

要提交到 App Store,您必须使用 Xcode 中包含的 Swift 版本构建您的应用程序。

Upload to apple connect probably reject by apple.

上传到苹果连接可能被苹果拒绝。