Closure use of non-escaping parameter 'xxx' may allow it to escape
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Closure use of non-escaping parameter 'xxx' may allow it to escape相关的知识,希望对你有一定的参考价值。
新版的Swift闭包做参数默认是@noescaping,不再是@escaping。所以如果函数里异步执行该闭包,要添加@escaping。否则报错:Closure use of non-escaping parameter ‘xxx‘ may allow it to escape.
func delay(seconds: Double, completion: @escaping () -> Void) { DispatchQueue.main.asyncAfter(deadline: .now() + seconds) { completion() } }
以上是关于Closure use of non-escaping parameter 'xxx' may allow it to escape的主要内容,如果未能解决你的问题,请参考以下文章