ios Swift 5.1.2 编译器无法导入使用 Swift 5.1 编译的模块

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

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

iosswiftxcodeswift5.1

提问by Orion Edwards

I have a framework (in this instance it's RxSwift) which I've compiled using Xcode 11.0 into the traditional RxSwift.frameworkstyle package

我有一个框架(在本例中是 RxSwift),我使用 Xcode 11.0 将其编译到传统RxSwift.framework样式包中

This imported fine into Xcode 11.0 and also 11.1 never had any problems with it

这很好地导入到 Xcode 11.0 和 11.1 中从未有任何问题

Today, upon Apple's release of Xcode 11.2, I upgraded, and I am presented with the error:

今天,在 Apple 发布 Xcode 11.2 后,我进行了升级,但出现了错误:

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

Swift 5.1.2 编译器无法导入使用 Swift 5.1 编译的模块

I'm used to swift compiler mismatches, and I'm aware I can just recompile RxSwift using Xcode 11.2 and carry on, but the headline feature of Swift 5.1 was module stability.

我习惯于 swift 编译器不匹配,我知道我可以使用 Xcode 11.2 重新编译 RxSwift 并继续,但 Swift 5.1 的主要特性是模块稳定性

I was under the impression that now that we have module stability, frameworks won't need to keep getting recompiled with every new Xcode release, yet this is clearly not the case.

我的印象是,现在我们有了模块稳定性,框架不需要随着每个新的 Xcode 版本不断重新编译,但显然情况并非如此。

If anyone can explain what is going on here I would much appreciate it. Is Xcode 11.2 exhibiting a bug? or did I somehow need to tell it I wanted module stability when I originally compiled with Xcode 11.0?

如果有人能解释这里发生了什么,我将不胜感激。Xcode 11.2 是否存在错误?或者当我最初使用 Xcode 11.0 编译时,我是否需要告诉它我想要模块稳定性?

回答by Orion Edwards

OK, Turns out if you watch the WWDC video, they explain it: https://developer.apple.com/videos/play/wwdc2019/416/

好的,如果您观看 WWDC 视频,他们会解释:https: //developer.apple.com/videos/play/wwdc2019/416/

You need to set the Build Libraries for Distributionoption to Yesin your framework's build settings, otherwise the swift compiler doesn't generate the neccessary .swiftinterfacefiles which are the key to future compilers being able to load your old library.

您需要在框架的构建设置中将Build Libraries for Distribution选项设置为Yes,否则 swift 编译器不会生成必要的.swiftinterface文件,这些文件是未来编译器能够加载旧库的关键。

This ends up in your project.pbxproj file as:

这最终在您的 project.pbxproj 文件中为:

BUILD_LIBRARY_FOR_DISTRIBUTION = YES;

After setting this flag, a framework I compiled using Xcode 11.0 (swift 5.1) was able to be used by Xcode 11.2 (swift 5.1.2) and everything appears to be working correctly.

设置此标志后,我使用 Xcode 11.0 (swift 5.1) 编译的框架可以被 Xcode 11.2 (swift 5.1.2) 使用,并且一切似乎都正常工作。

Hopefully this question/answer will serve as a useful reference for everyone who hasn't watched all the WWDC videos

希望这个问题/答案可以为所有没有看过所有 WWDC 视频的人提供有用的参考

If the error still persists go to Product> Clean Build Folderand Buildagain.

如果错误仍然存​​在,请转到产品>清理构建文件夹并再次构建

回答by Sergio

I had the same error importing 3rd party libraries. I fixed it using toolchains in Xcode and taking the release September 19 2019 from here https://swift.org/download/#releases. After that I had to re-import my libraries and it worked.

我在导入 3rd 方库时遇到了同样的错误。我使用 Xcode 中的工具链修复了它,并于 2019 年 9 月 19 日从这里https://swift.org/download/#releases 发布。之后我不得不重新导入我的库并且它起作用了。

回答by Rinni

This made my compiler error go away.

这使我的编译器错误消失了。

  1. carthage bootstrap --platform ios
  2. brew bundle
  3. pod repo update
  1. carthage bootstrap --platform ios
  2. brew bundle
  3. pod repo update

回答by iMoeNya

You can use Carthage to add the RxSwift framework.

您可以使用 Carthage 添加 RxSwift 框架。

Basically, Carthage gives you a similar traditional RxSwift.framework style package.

基本上,Carthage 为您提供了一个类似传统 RxSwift.framework 风格的包

Then try carthage update --no-use-binaries.

然后尝试carthage update --no-use-binaries