【发布时间】:2021-09-20 08:39:36
【问题描述】:
var currentCount = 0
let totalCount = 100
func myEscapingRecursiveFunction(_ json: String, done: @escaping (Bool) -> Void) {
currentCount+=1
if currentCount == totalCount {
done(true)
}
else {
myEscapingRecursiveFunction("xyz") { done in
// what should I do here????
}
}
通话
// (Initially called here)
myEscapingRecursiveFunction("xyz") { done in
if done {
print("completed") // I want to get response here after the recursion is finished
}
}
我希望我的函数仅在当前计数等于总计数时转义,否则它应该递归,问题是我想在最初调用它的地方得到响应,但它总是会在上次调用它的地方执行完成处理程序代码。这里:
【问题讨论】:
标签: ios swift recursion escaping closures