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()
    }
}

 

上一篇:解决最小化安装自动补齐问题(小白向)


下一篇:linux Completions 机制