运行 命中 return 之前的函数。 iOS, Swift,
Run a function before hitting return. iOS, Swift,
如果在到达 return 之前未满足保护语句,是否有方法 运行 函数?
guard let detectedRectangle = observations.first else {
functionToRun(completion: { (complete) in
print("Tony GOT TO RETURN"); return }
})
上面的代码让我把 return 放在完整的部分之外。
guard let detectedRectangle = observations.first else {
functionToRun(completion: { (complete) in
})
print("Tony GOT TO RETURN"); return }
我已将函数中的 3 个打印语句设置为 运行 在某些点上,它在点击 return 打印
之前达到了其中的 2 个
如果包含 guard
语句的函数具有与 functionToRun
相同的 return 类型,则您可以 return functionToRun
。示例:
func guardHolder() { // guardHolder returns Void
guard let detectedRectangle = observations.first else {
// so, if functionToRun also returns Void type, we can return this func
return functionToRun { _ in print("Tony GOT TO RETURN") }
}
}
如果在到达 return 之前未满足保护语句,是否有方法 运行 函数?
guard let detectedRectangle = observations.first else {
functionToRun(completion: { (complete) in
print("Tony GOT TO RETURN"); return }
})
上面的代码让我把 return 放在完整的部分之外。
guard let detectedRectangle = observations.first else {
functionToRun(completion: { (complete) in
})
print("Tony GOT TO RETURN"); return }
我已将函数中的 3 个打印语句设置为 运行 在某些点上,它在点击 return 打印
之前达到了其中的 2 个如果包含 guard
语句的函数具有与 functionToRun
相同的 return 类型,则您可以 return functionToRun
。示例:
func guardHolder() { // guardHolder returns Void
guard let detectedRectangle = observations.first else {
// so, if functionToRun also returns Void type, we can return this func
return functionToRun { _ in print("Tony GOT TO RETURN") }
}
}