用 Swift 4.1.2 编译的模块无法在 Swift 4.1.50 中导入:Xcode 10 错误

Module compiled with Swift 4.1.2 cannot be imported in Swift 4.1.50: Xcode 10 Error

Swift 4.2 出来了,我在使用 ObjectMapper 和其他一些 pods 时在我的项目中收到此错误消息:

Module compiled with Swift 4.1.2 cannot be imported in Swift 4.1.50

那么我如何告诉 Xcode 开始更新我的项目并将其迁移到 Swift 4.2?

Swift 4.2 中,隐式展开可选 (IUO) 的实现发生了变化,根据 swift blog 现在隐式解包可选 T!会被认为是T? with 和额外的标志,让编译器知道它是一个隐式解包可选。

The new mental model for IUOs is one where you consider ! to be a synonym for ? with the addition that it adds a flag on the declaration letting the compiler know that the declared value can be implicitly unwrapped.

由于此更改,可能存在一些源兼容性问题,可能需要您修改代码才能成功编译。

在Swift3中,像var a: Int这样的声明?将导致具有类型 Optional 和类似 var b: String! 的声明。将导致 b 具有 ImplicitlyUnwrappedOptional 类型。它在 Swift 4.2 中发生了变化,因此它显示 ObjectMapper 的 Xcode 10 的错误,swift 4.2 和 3.* 的 Xcode 也有类似的实现10.

在 Objectmapper 库中有一些函数声明在 swift 4.1 之前显示警告,现在在 swift 4.2 显示为错误。请参阅下图以了解 Xcode 9.4 和 swift 4.1

中的警告

ObjectMapper GitHub 存储库中有一些拉取请求已经解决了问题,但他们正在等待新的 Xcode beta 版本,因为它正在使用编译器指令 最近被接受的功能将与新的 Xcode 测试版一起发布。

更新: 此问题已在 ObjectMapper 3.3.0 版本中修复。

您需要在 terminal.And 中切换 Xcode beta 版本,删除项目中的旧版本 Carthage 文档。更新迦太基 carthage update --platform iOS --no-use-binaries.

您没有使用正确的 swift 版本编译 Carthage 模块。所以你需要:

  1. 确保您的终端指向您的 Xcode 10 Beta 应用程序而不是您的常规 Xcode:

sudo xcode-select -switch Xcode_beta_10.app

  1. 更新您的 Carthage 文件:

carthage update --platform iOS --no-use-binaries

  1. 返回 Xcode 中的项目,清理,构建

运行 使用终端在您的项目目录中执行以下命令。它将更新您的广告连播。希望能解决你的问题。

pod update ObjectMapper

我对 Alamofire 也有同样的问题。

我的修复是

  1. 清理我的构建
  2. 转到 File/Workspace Settings 并确保您为 Build System 使用 Legacy Build System。然后问题就解决了。