新版的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() } }