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的主要内容,如果未能解决你的问题,请参考以下文章

php匿名函数和闭包函数及use关键字传参及Closure匿名函数类

Error in cool_function[1] : object of type ‘closure‘ is not subsettable

php的闭包(Closure)也就是匿名函数。是PHP5.3引入的。

遇到问题--spark-scala---Cannot resolve overloaded method ‘udf‘--Defines a Scala closure of 11 arguments

遇到问题--spark-scala---Cannot resolve overloaded method ‘udf‘--Defines a Scala closure of 11 arguments(

遇到问题--spark-scala---Cannot resolve overloaded method ‘udf‘--Defines a Scala closure of 11 arguments(