xcode 无法在 swift 3.1 中导入使用 swift 4.0 编译的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44475274/
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.0 cannot be imported in swift 3.1
提问by Dominique Vial
Apparently I have managed to build my project in Xcode 9 beta and now I only get the error
显然我已经设法在 Xcode 9 beta 中构建我的项目,现在我只收到错误
Module compiled with swift 4.0 cannot be imported in swift 3.1
无法在 swift 3.1 中导入使用 swift 4.0 编译的模块
When I run the project in Xcode 8. The module in my case are Alamofire. I have tried to restart Xcode but nothing happens any ideas how to solve this issue?
当我在 Xcode 8 中运行项目时。我的模块是 Alamofire。我试图重新启动 Xcode,但没有任何反应任何想法如何解决这个问题?
回答by Rashwan L
You have two options that you can do:Clean
the project and then try to re-build
your solution and see if it works.
您有两个选项可以做:Clean
项目,然后尝试re-build
您的解决方案,看看它是否有效。
If it don′t work and you still get the same error message then do the following steps and it should work for you:
如果它不起作用并且您仍然收到相同的错误消息,请执行以下步骤,它应该适合您:
- Open your
podfile
and removeAlamofire
- Run
pod update
- Re-add
Alamofire
to yourpodfile
- Run
pod update
- When this is done,
clean
your project and run it
- 打开
podfile
并删除Alamofire
- 跑
pod update
- 重新添加
Alamofire
到您的podfile
- 跑
pod update
- 完成后,
clean
您的项目并运行它
回答by Dominique Vial
Same problem here but using Carthage. And here is the answer:
同样的问题,但使用迦太基。这是答案:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
- delete the
Carthage
folder for the project - Update Carthage:
carthage update --platform iOS
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
- 删除
Carthage
项目的文件夹 - 更新迦太基:
carthage update --platform iOS
And voilà!
瞧!
回答by Tata Grigory
I had the same problem and cleaning the build folder helped:
我遇到了同样的问题,清理构建文件夹有帮助:
Command+Option+Shift+K
or
或者
Product
-> Option+Clean
Product
-> Option+Clean
回答by Harsha
Just deleting Derived data worked for me, no need to do Pod install again
只是删除派生数据对我有用,无需再次安装 Pod
回答by infinity_coding7
I met this problem in a project where dependency is managed by Carthage. In my case, I didn't set command line tool in xcode (Type in xcodebuild -version, you will know whether you set it up or not), so first step is to go to XCode --> Preference --> Locations then select the xcode you want to serve as command line tool. Then you can follow the steps that @Domsware mentioned above to rebuild all frameworks you are gonna use.
我在 Carthage 管理依赖项的项目中遇到了这个问题。在我的例子中,我没有在 xcode 中设置命令行工具(输入 xcodebuild -version,你会知道你是否设置了它),所以第一步是去 XCode --> Preference --> Locations 然后选择要用作命令行工具的 xcode。然后您可以按照@Domsware 上面提到的步骤重建您要使用的所有框架。
===============================================
================================================
Same problem here but using Carthage. And here is the answer:
同样的问题,但使用迦太基。这是答案:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
delete the Carthage folder for the project
Update Carthage: carthage update --platform iOS
===============================================
================================================
Then don't forget to delete old links under 'Linked frameworks and libraries' and drag all frameworks from /Carthage folder under you project to 'Linked frameworks and libraries'.
然后不要忘记删除“链接的框架和库”下的旧链接,并将所有框架从您项目下的 /Carthage 文件夹拖到“链接的框架和库”。
Then voilà!
然后瞧!
For those who are using CocoaPods, I suspect (Disclaimer: I didn't encounter this problem in project where CocoaPods is the dependency manager) the solution would be run the following command in terminal:
对于那些使用 CocoaPods 的人,我怀疑(免责声明:我在 CocoaPods 是依赖管理器的项目中没有遇到这个问题)解决方案将在终端中运行以下命令:
$ pod deintegrate
$ pod clean
$ pod install
where you might need to install 'deintegrate' and 'clean' tool for CocoaPod
您可能需要为 CocoaPod 安装“deintegrate”和“clean”工具
$ sudo gem install cocoapods-deintegrate cocoapods-clean
more details see post How to remove CocoaPods from a project?
更多详细信息请参阅帖子 如何从项目中删除 CocoaPods?
回答by Shubham Mishra
Add following lines at the end of your pod file:
在 pod 文件的末尾添加以下几行:
post_install do |installer|
print "Setting the default SWIFT_VERSION to 4.0\n"
installer.pods_project.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
installer.pods_project.targets.each do |target|
if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
print "Setting #{target}'s SWIFT_VERSION to 3.0\n"
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
else
print "Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n"
target.build_configurations.each do |config|
config.build_settings.delete('SWIFT_VERSION')
end
end
end
end