gpt4 book ai didi

从 Swift 3 转换到 Swift 4 - Void 需要 2 个参数

转载 作者:搜寻专家 更新时间:2023-11-01 06:51:08 27 4
gpt4 key购买 nike

我在 Swift 4 中遇到错误,但不太确定 Xcode 的预期结果。

这段代码:

_connection.on(method: "locationUpdate", callback: {(locationUpdate: LocationUpdate) in
self.locationUpdateReceived(locationUpdate)
})

产生这个错误:

Contextual closure type '([Any?], TypeConverter) -> Void' expects 2 arguments, but 1 was used in closure body

最佳答案

你可以试试

_connection.on(method: "locationUpdate", callback: { locationUpdate, other in
self.locationUpdateReceived(locationUpdate)
})

_connection.on(method: "locationUpdate") { locationUpdate, other in
self.locationUpdateReceived(locationUpdate)
}

如果您不想使用 other 参数,最好的做法是不分配它,如下所示:

_connection.on(method: "locationUpdate") { locationUpdate, _ in
self.locationUpdateReceived(locationUpdate)
}

关于从 Swift 3 转换到 Swift 4 - Void 需要 2 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56938581/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com