【问题标题】:Invalid conversion from throwing function of type '(_) throws -> ()' to non-throwing function type '(CallResult) -> Void'从 '(_) throws -> ()' 类型的抛出函数到非抛出函数类型 '(CallResult) -> Void' 的无效转换
【发布时间】:2018-12-19 23:11:55
【问题描述】:

有以下代码块:

do {
  try call.receiveMessage { callResult in
    if let msg = try callResult.resultData {
      let result = try decoder.decode(valueType, from: msg)
    }
    // other stuff
} catch let error {
  if let callback = self.onError {
    callback(error)
  }
}

由于try call.receieveMessage 的错误导致编译失败:

从 '(_) throws -> ()' 类型的抛出函数到非抛出函数类型 '(CallResult) -> Void' 的无效转换

我调用的函数确实有签名改变:

from: public func receiveMessage(completion: @escaping (Data?) throws -> Void) throws { to: public func receiveMessage(completion: @escaping (CallResult) -> Void) throws {

让我难以理解的是同一方法的其他调用没有问题,所以我还没有完全确定是什么让这个特定的块特别。

任何建议将不胜感激。

【问题讨论】:

    标签: swift


    【解决方案1】:

    应该坐久一点。解决方法是用 do/catch 包装 lambda。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      相关资源
      最近更新 更多