我应该在自我被释放时调用完成处理程序吗
Should I call completion handler when self is deallocated
我们可能都使用过下面的模式。这可能无关紧要,我只是好奇当 self
不再存在时我是否仍应调用完成处理程序?
var uid: String
func asyncTask(completion: @escaping(Result)->()) {
anotherAsyncTask() { [weak self] (result) in
guard let uid = self?.uid else {
completion(.error) // Should I call this???
return
}
// consume result
}
}
由于 self
已取消初始化,因此调用
没有任何意义
completion(.error) // Should I call this???
因为结果已经在这里了return
就足够了
我们可能都使用过下面的模式。这可能无关紧要,我只是好奇当 self
不再存在时我是否仍应调用完成处理程序?
var uid: String
func asyncTask(completion: @escaping(Result)->()) {
anotherAsyncTask() { [weak self] (result) in
guard let uid = self?.uid else {
completion(.error) // Should I call this???
return
}
// consume result
}
}
由于 self
已取消初始化,因此调用
completion(.error) // Should I call this???
因为结果已经在这里了return
就足够了