解决此完成块 [英] Solve this completion Block
本文介绍了解决此完成块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解决此完成问题,但是我一直在警告很多。
i'm try to solve this completion block, but I keep having many warning.
Xcode给我警告
无法将类型'()'的返回表达式转换为类型'[AirportModel]'
Cannot convert return expression of type '()' to return type '[AirportModel]'
对不起,我是一个初学者...在关闭过程中有点迷失了...
Sorry I'm a beginner... little lost on this closure...
我必须返回 AirportModel的向量
为了显示在swiftUI的列表中,我想使用 DispatchQueue
以避免在搜索时阻塞视图:
I have to return this vector of AirportModel
in order to be display in a list in swiftUI, I want use DispatchQueue
in order to avoid to block the view while searching:
func filter (valoreSearhed: String, arrayTosearh: AirportVector, completionBlock: (_ airports: [AirportModel]) -> Void) -> [AirportModel] {
DispatchQueue.global().async {
let results = arrayTosearh.filter { $0.aptICAO.localizedCaseInsensitiveContains(valoreSearhed) }
completionBlock(results)
}
}
推荐答案
我认为它应该返回临时空数组,因此我建议使用以下
I assume by intention it should return temporary empty array, so I'd recommend the following
func filter (valoreSearhed: String, arrayTosearh: AirportVector, completionBlock: @escaping (_ airports: [AirportModel]) -> Void) -> [AirportModel] {
DispatchQueue.global().async {
let results = arrayTosearh.filter { $0.aptICAO.localizedCaseInsensitiveContains(valoreSearhed) }
completionBlock(results)
}
return []
}
这篇关于解决此完成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文