使用Swift 5.1编译的模块不能由Swift 5.1.2编译器导入 [英] Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

查看:245
本文介绍了使用Swift 5.1编译的模块不能由Swift 5.1.2编译器导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这很好地将其导入Xcode 11.0,并且11.1也从未遇到过任何问题

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

今天,在Apple发布Xcode 11.2之后,我进行了升级,并看到以下错误消息:

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

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

我习惯于快速编译器不匹配,并且我知道我可以使用Xcode 11.2重新编译RxSwift并继续进行,但是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.

给我的印象是,既然我们已经有了模块稳定性,那么框架就不需要在每个新的Xcode版本中都进行重新编译了,但是显然情况并非如此.

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 11.2是否存在错误?还是我最初用Xcode 11.0编译时需要以某种方式告诉我我想要模块的稳定性?

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?

推荐答案

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

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

您需要在框架的构建设置中将用于分发的构建库选项设置为,否则,swift编译器不会生成必要的.swiftinterface文件是将来的编译器能够加载您的旧库的关键.

You need to set the Build Libraries for Distribution option to Yes in your framework's build settings, otherwise the swift compiler doesn't generate the neccessary .swiftinterface files which are the key to future compilers being able to load your old library.

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

This ends up in your project.pbxproj file as:

BUILD_LIBRARY_FOR_DISTRIBUTION = YES;

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

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.

希望这个问题/答案将为所有未观看所有WWDC视频的人提供有用的参考

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

如果错误仍然存​​在,请转至产品> 清洁构建文件夹,然后再次构建.

If the error still persists go to Product > Clean Build Folder and Build again.

这篇关于使用Swift 5.1编译的模块不能由Swift 5.1.2编译器导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆