ios Xcode 9:无法在 Swift 4.0 中导入使用 Swift 3.1 编译的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44399109/
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
Xcode 9 : Module compiled with Swift 3.1 cannot be imported in Swift 4.0
提问by Arnaud
After updating to Xcode 9, I tried to build one of my projects.
更新到 Xcode 9 后,我尝试构建我的一个项目。
I use the FacebookLoginpod. I have a compiler error in FacebookLogin/LoginButton.swift
我使用FacebookLogin窗格。我在 FacebookLogin/LoginButton.swift 中有一个编译器错误
@testable import FacebookCore
? Module compiled with Swift 3.1 cannot be imported in Swift 4.0
In my target's build settings, the Swift language version is set to Swift 3.2.
在我的目标构建设置中,Swift 语言版本设置为Swift 3.2。
I guess I need to wait for Facebook to update their pod ? Or any other suggestion ?
我想我需要等待 Facebook 更新他们的 pod 吗?或任何其他建议?
Thanks !
谢谢 !
回答by xavi.pedrals
Update:
更新:
Solution also tested and working in Swift 5 and Xcode 11.
解决方案还在 Swift 5 和 Xcode 11 中进行了测试和工作。
Original:
原来的:
I would like to add that if you are using Carthageto compile a module in Swift 3.2 you should go to a terminal and run:
我想补充一点,如果您使用Carthage在 Swift 3.2 中编译模块,您应该转到终端并运行:
sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer
To use the Xcode 9 command line tools, then you can run:
要使用 Xcode 9 命令行工具,您可以运行:
carthage update NameOfTheLibrary --platform iOS --no-use-binaries
This will compile the library with your current command line tools, it can be a bit slow but now the project should build.
这将使用您当前的命令行工具编译库,它可能有点慢,但现在项目应该构建了。
Note
笔记
To revert and use your stable Xcode command line tools simply run:
要恢复和使用稳定的 Xcode 命令行工具,只需运行:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
回答by klinger
Xcode 9 comes with a Swift 4 compiler that understands both Swift 3.2 and swift 4, it even lets you mix and match between the 2 versions. Unfortunately, other versions aren't supported.
Xcode 9 带有一个 Swift 4 编译器,它可以理解 Swift 3.2 和 Swift 4,它甚至可以让你在这两个版本之间混合和匹配。不幸的是,不支持其他版本。
Even if you set your language to Swift 3.2, it uses the Swift 4 compiler.
即使您将语言设置为 Swift 3.2,它也会使用 Swift 4 编译器。
If you're using cocoapods, you can add this to the end of your pod file to force the pods to use Swift 3.2 or 4.0:
如果您使用的是 cocoapods,您可以将其添加到 pod 文件的末尾以强制 pod 使用 Swift 3.2 或 4.0:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
Alternatively, you could put the files from the pod directly into your project temporarily, until FacebookLogin is updated to Swift 3.2 or 4.
或者,您可以暂时将 pod 中的文件直接放入您的项目中,直到 FacebookLogin 更新为 Swift 3.2 或 4。
Note: Edited based on Matt's feedback
注意:根据 Matt 的反馈进行编辑
回答by TomorJM
Maybe you can clean the target before you build it. It works fine for me.
也许您可以在构建目标之前清理目标。这对我来说可以。
回答by Xu Yin
I ran into the same issue on Xcode 9 Beta 3, which pointing to 'Alamofire' and tried a few different solutions, the easiest one i found is
我在 Xcode 9 Beta 3 上遇到了同样的问题,它指向“Alamofire”并尝试了几种不同的解决方案,我发现最简单的一个是
1. CMD+SHIFT+K to clean the build
2. Restart Xcode 9 <-- make sure you do this step, that's critical. `
回答by John Pavley
Doing a "clean build folder" and restarting Xcode 9 cleaned up the error for me. Also the error didn't stop the app from running on my device or the simulator.
执行“清理构建文件夹”并重新启动 Xcode 9 为我清除了错误。此外,该错误并未阻止应用程序在我的设备或模拟器上运行。
回答by SwiftDeveloper
If using Carthage, Open terminaland;
如果使用Carthage,打开终端和;
carthage update --platform iOS --no-use-binaries
If using Pod, Open terminaland;
如果使用Pod,打开终端;
pod update
(Also if don't work in pod, you can change SWIFT_VERSION in podfile Ex:
(此外,如果在 pod 中不起作用,您可以在 podfile 中更改 SWIFT_VERSION 例如:
config.build_settings['SWIFT_VERSION'] = '3.2'
)
)
After;
后;
Open Xcode and use;
打开Xcode并使用;
Command+Option+Shift+K
回答by reco
goto xcode DerivedData directory then remove all file inside it and recompile your project . it work for me .
转到 xcode DerivedData 目录,然后删除其中的所有文件并重新编译您的项目。它对我有用。
and default DerivedData directory is :~/Library/Developer/Xcode/DerivedData.
默认的 DerivedData 目录是:~/Library/Developer/Xcode/DerivedData。
回答by RayJiang
It works for me.
这个对我有用。
1.Clean your project in Xcode 8
1.在 Xcode 8 中清理你的项目
2.Build or run your project in Xcode 9
2.在 Xcode 9 中构建或运行您的项目
回答by Shan Ye
I cleaned the project in Xcode 9, and then run the app, it works.
我在 Xcode 9 中清理了项目,然后运行该应用程序,它工作正常。
回答by Vineesh TP
Clean Build Folder
清理构建文件夹
Cmd + option + shift + K