xcode Swift 4.2 编译器无法导入使用 Swift 4.1.2 编译的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52413437/
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
Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler
提问by Heliotropix
Short story: Xcode 10 is set to Swift 4, but it is using Swift 4.2.
小故事:Xcode 10 设置为 Swift 4,但它使用的是 Swift 4.2。
Long story: Our project is not ready for Swift 4.2, since our dependent frameworks are not Swift 4.2, yet. But, I would like to, at least, use Xcode 10.
长话短说:我们的项目还没有为 Swift 4.2 做好准备,因为我们的依赖框架还不是 Swift 4.2。但是,我想至少使用 Xcode 10。
- I have Xcode 9.4.1 and Xcode 10 installed.
- I have Command Line Tools set to use Xcode 9.4.1:
- 我安装了 Xcode 9.4.1 和 Xcode 10。
- 我将命令行工具设置为使用 Xcode 9.4.1:
- In Xcode 10, I have the project setting, Swift Language Version, set to Swift 4.
- 在 Xcode 10 中,我将项目设置 Swift Language Version 设置为 Swift 4。
- I have verified on the command line the Swift version the shell is using is 4.1.2:
- 我已经在命令行上验证了 shell 使用的 Swift 版本是 4.1.2:
"swift --version Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)"
“swift --version Apple Swift 版本 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)”
- I've run carthage update.
- I've quit Xcode 10 and relaunched.
- I have deep cleaned and deleted Derived Data.
- I build and I get this error:
- 我已经运行了迦太基更新。
- 我已经退出 Xcode 10 并重新启动。
- 我已经深度清理并删除了派生数据。
- 我构建并收到此错误:
"Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler: .../App/Carthage/Build/iOS/RealmSwift.framework/Modules/RealmSwift.swiftmodule/arm64.swiftmodule"
“使用 Swift 4.1.2 编译的模块无法被 Swift 4.2 编译器导入:.../App/Carthage/Build/iOS/RealmSwift.framework/Modules/RealmSwift.swiftmodule/arm64.swiftmodule”
To me, this indicates that I have my intended Swift version (4.1.2) set correctly and Xcode is still trying to use the wrong version of Swift (4.2).
对我来说,这表明我的预期 Swift 版本 (4.1.2) 设置正确,而 Xcode 仍在尝试使用错误版本的 Swift (4.2)。
Does anyone have suggestions on how to resolve this? Am I missing something? Xcode bug?
有没有人有关于如何解决这个问题的建议?我错过了什么吗?Xcode 错误?
回答by FreeNickname
I'm not positive, but my guess is that this is the reason:
我不是很乐观,但我的猜测是这就是原因:
I have Command Line Tools set to use Xcode 9.4.1
我将命令行工具设置为使用 Xcode 9.4.1
You have to recompile your Swift 4 dependencies using Xcode 10, because Swift is not ABI-stable, i.e. binaries compiled with different compiler versions are not compatible. And even Swift 4.0 binaries compiled with different versions of Xcode may not be compatible.
您必须使用 Xcode 10 重新编译 Swift 4 依赖项,因为 Swift不是 ABI-stable,即使用不同编译器版本编译的二进制文件不兼容。甚至用不同版本的 Xcode 编译的 Swift 4.0 二进制文件也可能不兼容。
I don't have much experience with Carthage, but my guess is that you should use Xcode 10 as a command-line tool, but you have to set a different Swift language version to be used by Xcode 10. It should probably be specified in the project (in this case RealmSwift), or using environment variables, but you'll need someone else to answer with more details, I'm afraid.
我对 Carthage 没有太多经验,但我的猜测是您应该使用 Xcode 10 作为命令行工具,但您必须设置不同的 Swift 语言版本以供 Xcode 10 使用。它可能应该在项目(在本例中为 RealmSwift),或使用环境变量,但恐怕您需要其他人来回答更多细节。
回答by Andreea Lavinia Ionescu
Using Realm with Xcode 10 requires building it from source. In Terminal write:
在 Xcode 10 中使用 Realm 需要从源代码构建它。在终端写:
git clone --recursive https://github.com/realm/realm-cocoa.git
cd realm-cocoa
sh build.sh ios-swift
回答by lingyfh
you can use multiple swift toolchains. download url swift toolchain downloadafter you install some version. restart your xcode, in xocde menu you can see toolchains option.
您可以使用多个 swift 工具链。安装某个版本后,下载 url swift 工具链下载。重新启动您的 xcode,在 xocde 菜单中您可以看到工具链选项。
回答by regina_fallangi
I had the same problem and then I realised I had not selected Xcode 10 as my Xcode
. Try:
我遇到了同样的问题,然后我意识到我没有选择 Xcode 10 作为我的Xcode
. 尝试:
sudo xcode-select -s /Applications/Xcode10.app
Also, if you will be switching between Xcode9 and 10, I recommend you the following: If you change from 9 to 10, run mv Carthage Carthage9
and then rebuild Carthage. Whenever you want to switch back, move Carthage to Carthage10
and do mv Carthage9 Carthage
. This will save you lots of time building.
另外,如果您要在 Xcode9 和 10 之间切换,我建议您执行以下操作:如果您从 9 更改为 10,请运行mv Carthage Carthage9
并重建 Carthage。每当您想切换回来时,将 Carthage 移动到Carthage10
并执行mv Carthage9 Carthage
。这将为您节省大量构建时间。