在 Swift 中,如果我在一个闭包内,它本身在另一个函数内,有没有办法退出函数本身?
这是一个使用 GCDKit 库中的闭包的示例。
func test() {
GCDQueue.Default.async {
print("Print me!")
return //Is there a statement that does this?
}.notify(.Main) {
print("Never print me.")
}
}
最佳答案
不,没有。闭包在独立的环境中运行。如您所知,在执行闭包时,调用 test()
的线程不再执行 test()
方法。
关于swift - swift 可以退出 root 闭包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514555/