xcode 无法在 Swift 2.3 中导入使用 Swift 3.0 编译的模块

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

Module compiled with Swift 3.0 cannot be imported in Swift 2.3

iosswiftxcode

提问by Bart?omiej Semańczyk

This is what I do:

这就是我所做的:

import BSTableViewReorder

and get the following error:

并得到以下错误:

Module compiled with Swift 3.0 cannot be imported in Swift 2.3

无法在 Swift 2.3 中导入使用 Swift 3.0 编译的模块

What can I do to make it compile? I did:

我该怎么做才能让它编译?我做了:

Edit > Convert -> Current Swift Syntax

Using Xcode 8 and macOS Sierra.

使用 Xcode 8 和 macOS Sierra。

For Both: the target and the project I have the following settings of Use Legacy Swift Language Version

对于两者:目标和项目我有以下设置 Use Legacy Swift Language Version

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

The project is my pod for cocoapods dependencies. I just converted project to Swift 3.0 but it does not compile.

该项目是我的 cocoapods 依赖项的 pod。我刚刚将项目转换为 Swift 3.0,但它无法编译。

采纳答案by Eugen Dimboiu

You'll need to change the Use Legacy Swift Language Versionto NO- this makes sure your project will use swift 3.

您需要更改Use Legacy Swift Language VersionNO- 这确保您的项目将使用 swift 3。

If you want to package your project as a POD (for cocoapods) you'll need to add a file named .swift-version (containing 1 single line, "3.0"). This will tell cocoapods to use the swift 3 compiler.

如果要将项目打包为 POD(用于 cocoapods),则需要添加一个名为 .swift-version 的文件(包含 1 行“3.0”)。这将告诉 cocoapods 使用 swift 3 编译器。

Everything should work after this changes.

在此更改后,一切都应该正常工作。

回答by Payal

If you are using any third party frameworks just update them once for Xcode 8.1 and change the Use Legacy Swift Language Version to NO.

如果您使用任何第三方框架,只需为 Xcode 8.1 更新一次,并将 Use Legacy Swift Language Version 更改为 NO。

回答by shoe

in my case, the framework developers added this line in the code that was intended for the Podfile:

就我而言,框架开发人员在代码中添加了这一行,用于Podfile

config.build_settings['SWIFT_VERSION'] = '2.3' # or '3.0'

as you can see, they defaulted to '2.3', which caused problems because i was running 3.0. simply removing the '2.3' # orand leaving the '3.0'fixed the problem.

如您所见,它们默认为“2.3”,这导致了问题,因为我运行的是 3.0。只需删除'2.3' # or并留下'3.0'固定的问题。

回答by mtc

If the above suggestions don't work for you try deleting ~Library/Developer/Xcode/DerivedData

如果以上建议对您不起作用,请尝试删除 ~Library/Developer/Xcode/DerivedData