例如
func hello() -> Bool {
var result = false
httpRequestWithCompletionHandler({ is404 in
result = is404
})
return result
}
这个函数的返回值永远是 false,因为 closure 是异步执行的
怎么在调用这个函数的时候,得到真正的返回值呢?
注: result 必须定义在函数体内,不能定义在函数体外
例如
func hello() -> Bool {
var result = false
httpRequestWithCompletionHandler({ is404 in
result = is404
})
return result
}
这个函数的返回值永远是 false,因为 closure 是异步执行的
怎么在调用这个函数的时候,得到真正的返回值呢?
注: result 必须定义在函数体内,不能定义在函数体外
2 回答771 阅读
595 阅读
这样?