转换为当前 Swift 语法失败 - “没有这样的模块”(Swift 4,Xcode 9)

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

Convert to Current Swift Syntax Failed - "No such module" (Swift 4, Xcode 9)

iosswiftxcodeswift4xcode9

提问by Nikolay Suvandzhiev

In Xcode 9, I am trying to do the automatic conversion to Swift 4. It fails with the following message:

在 Xcode 9 中,我尝试自动转换为 Swift 4。它失败并显示以下消息:

enter image description here

在此处输入图片说明

Convert to Current Swift Syntax Failed
Please ensure that all selected targets build successfully with the currently configured Swift version before attempting a migration.

转换为当前 Swift 语法失败
在尝试迁移之前,请确保所有选定的目标都使用当前配置的 Swift 版本成功构建。

It's complaining of a missing module. But when I do a regular build there are no issues. Not sure if this is relevant, but the module (which Xcode is complaining is missing) was already converted to Swift 4 earlier (in it's own project).

它抱怨缺少模块。但是当我进行常规构建时,没有问题。不确定这是否相关,但该模块(Xcode 抱怨缺少该模块)早先已转换为 Swift 4(在它自己的项目中)。

Note: No Cocoapods / Carthage used here.

注意:这里没有使用 Cocoapods / Carthage。

Note: Two solutions tried (and worked) but do not address the underlying issue.

注意:两种解决方案尝试(并有效)但没有解决根本问题。

  • One solution is to do the conversion manually (change Swift version to 4 in build setting and apply Fix-Its one by one until no more build errors).
  • Another solution is to disable the third party framework (comment out all code where it's used), do the auto-migration, and then re-enable the framework. This could get pretty difficult with bigger projects.
  • 一种解决方案是手动进行转换(在构建设置中将 Swift 版本更改为 4 并一一应用 Fix-It,直到不再出现构建错误)。
  • 另一种解决方案是禁用第三方框架(注释掉所有使用它的代码),执行自动迁移,然后重新启用该框架。对于更大的项目,这可能会变得非常困难。

回答by Luca Davanzo

I can't find any solution yet.

我还找不到任何解决方案。

For now I fix manually setting Swift Language Version

现在我修复手动设置 Swift Language Version

enter image description here

在此处输入图片说明

After changing from 3.2 to 4.0 I compile and fix errors and warnings manually.
I'm waiting for a better solution!

从 3.2 更改为 4.0 后,我手动编译并修复错误和警告。
我正在等待更好的解决方案!

回答by Padavan

I also got this problem while converting my project to Swift 4.0. Looks like problem appears when you try to convert target which imports a framework which is already in Swift 4.0. At your screenshot you try to convert 'RecipeTextParser' which imports 'SovaTools' which is already Swift 4.0.

我在将项目转换为 Swift 4.0 时也遇到了这个问题。当您尝试转换导入 Swift 4.0 中已有框架的目标时,似乎会出现问题。在您的截图中,你尝试“转换RecipeTextParser”的进口“ SovaTools”,这已经是斯威夫特4.0。

I found dirty, but working solution. You can use older(Swift 3.2) version of 'SovaTools' when converting. You should NOTcheck it's mark in target selection window of conversion tool. Then, when 'RecipeTextParser' will be successfully converted you can use Swift 4.0 'SovaTools' version again.

我发现肮脏但有效的解决方案。转换时您可以使用较旧的(Swift 3.2)版本的“ SovaTools”。你应该检查它的标记在转换工具的目标选择窗口。然后,当“ RecipeTextParser”成功转换后,您可以再次使用 Swift 4.0 的“ SovaTools”版本。

回答by niladri

I got this error and in my case one of my Pods(the one Xcode was complaining about) was a Swift 4 target and the rest were Swift 3.2. Looking at the build logs it looks like Xcode built that framework in one location and was searching for it in another. When I reverted that Pod to an older version(that used Swift3.2) the problem went away. Obviously a Xcode bug. HTH

我遇到了这个错误,就我而言,我的一个 Pod(Xcode 抱怨的那个)是 Swift 4 目标,其余的是 Swift 3.2。查看构建日志,看起来 Xcode 在一个位置构建了该框架,并在另一个位置搜索它。当我将该 Pod 恢复到旧版本(使用 Swift3.2)时,问题就消失了。显然是Xcode错误。HTH

回答by Arqam Butt

Just update your pod and it will resolve the issue.

只需更新您的 pod,它就会解决问题。

To update pod:

更新 pod:

  • open terminal and go to your project directory
  • type pod update
  • 打开终端并转到您的项目目录
  • 输入 pod 更新

This resolved my issue.

这解决了我的问题。

回答by Krunal

Xcode (Xcode 9) language migration feature is not as much accurate that it can migrate your complete code/project from one swift version to another with zero tolerance. It skips few code migration for us (developers). It may be bug or inaccuracy of tool. But you need to put some manual effort also, to completely migrate swift language version for your project/code.

Xcode (Xcode 9) 语言迁移功能并不准确,以至于它可以零容忍地将您的完整代码/项目从一个 swift 版本迁移到另一个版本。它为我们(开发人员)跳过了一些代码迁移。这可能是工具的错误或不准确。但是您还需要进行一些手动操作,才能为您的项目/代码完全迁移 swift 语言版本。

Now, according to your snapshot, Xcode is showing and error for 'RecipeTextParser' framework. I think this is an external/third party framework. Another point to note, you've integrated this framework using CocoaPods:

现在,根据您的快照,Xcode 显示“RecipeTextParser”框架错误。我认为这是一个外部/第三方框架。还有一点要注意,您已经使用 CocoaPods 集成了这个框架:

Any one of following can be reason for failure of code migration:

以下任何一种都可能是代码迁移失败的原因:

  1. CocoaPods locks framework (files) for editing. So language migration process may not be able to migrate (or identify) code for external/thirdparty framework.
  2. In general terms, Framework is package of code files, so framework itself may not allow file/source code editing.
  1. CocoaPods 锁定框架(文件)以进行编辑。因此语言迁移过程可能无法迁移(或识别)外部/第三方框架的代码。
  2. 一般而言,Framework 是代码文件的包,因此Framework 本身可能不允许文件/源代码编辑。

Suggestion as solution:

建议作为解决方案:

  1. Update your cocoa pods as well as all frameworks integrated using cocoa pods compatible to latest swift language version.
  2. If you've manually integrated/added external/third party frameworks, then you need to update/replace those also.
  1. 更新您的可可豆荚以及使用与最新 swift 语言版本兼容的可可豆荚集成的所有框架。
  2. 如果您手动集成/添加了外部/第三方框架,那么您还需要更新/替换它们。

Some manual effort is required to completely migrate code between swift languages. I tried swift migration with above options and my all projects are now compatible with swift 4.

在 swift 语言之间完全迁移代码需要一些手动工作。我尝试使用上述选项进行快速迁移,我的所有项目现在都与 swift 4 兼容。