swift - 从 '(_) throws -> ()' 类型的抛出函数到非抛出函数类型 '(CallResult) -> Void' 的无效转换
问题描述
有以下代码块:
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' 的无效转换
我正在调用的函数确实有签名更改:
来自:public func receiveMessage(completion: @escaping (Data?) throws -> Void) throws { to: public func receiveMessage(completion: @escaping (CallResult) -> Void) throws {
我难以理解的是,相同方法的其他调用没有问题,所以我还没有完全确定是什么让这个特定的块特别。
任何意见,将不胜感激。
解决方案
应该坐久一点。解决方案是用 do/catch 包装 lambda。
推荐阅读
- mongodb - 基于另一个集合更新集合的字段 - MongoDB
- php - prettus 验证器无法正确验证日期
- python - 如何在 Python 中使用 matplotlib 绘制一条最佳拟合线?
- image - Tomcat 图像加载失败
- excel - 使用循环从一个工作簿复制到另一个工作簿
- arrays - 无法获得数组Angular中的第一项
- html - 删除 Jekyll 页面上的元素
- java - 为什么在导入 com.sun.management.OperatingSystemMXBean 时显示错误
- outlook - 带有多个日历的 Outlook:如何使用 VBA 确定选定的日历?
- reactjs - npm create-react-app 等待很长时间后无法完成