我有一个extension Array
形式为:
extension Array
{
private func someFunction(someClosure: (() -> Int)?)
{
// Do Something
}
func someOtherFunction(someOtherClosure: () -> Int)
{
someFunction(someClosure: someOtherClosure)
}
}
但我收到错误:Passing non-escaping parameter 'someOtherClosure' to function expecting an @escaping closure
.
两个闭包确实都是非转义的(默认情况下),并且显式添加@noescape
to someFunction
产生一条警告,表明这是 Swift 3.1 中的默认设置。
知道为什么我会收到此错误吗?
-- UPDATE --
Screenshot attached:
![enter image description here](https://i.stack.imgur.com/7acVN.png)
可选的闭包总是会逃逸。
这是为什么?这是因为可选的(它是一个枚举)包装了闭包并在内部保存它。
有一篇关于怪癖的优秀文章@escaping
here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)