Trouble with non-escaping closures in Swift 3

后端 未结 3 2043
清酒与你
清酒与你 2021-01-19 03:48

I have an extension Array in the form of:

extension Array
{
    private func someFunction(someClosure: (() -> Int)?)
    {
        // Do Some         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 04:36

    Optional closures are always escaping.

    Why is that? That's because the optional (which is an enum) wraps the closure and internally saves it.

    There is an excellent article about the quirks of @escaping here.

提交回复
热议问题