【发布时间】:2021-05-17 19:29:22
【问题描述】:
我有以下代码,我收到 completionHandler 错误
没有更多上下文,表达类型不明确
我知道这是由于completionHandler 不匹配造成的。如何为 completionHandler 返回错误的字符串/有意义的详细信息?
func fetch(urlString: String, completionHandler: @escaping (T?, Error?) -> Void) -> Void {
//...
guard let url = URL(string: urlString) else {
print("Failed to create URL!")
DispatchQueue.main.async {
completionHandler(nil, "Bad URL") // gives error: Type of expression is ambiguous without more context
}
return
}
}
【问题讨论】:
标签: ios swift completionhandler