How to cause non-exclusive closure inside local closure?

I have a function that looks something like this:

func test(closure: () -> ()) {
    let localClosure = { closure() }

    localClosure()
}

This is just an example and does not fully reflect the problem I am facing, obviously here I could just call closuredirectly!

It should be clear that the above code closurecannot exit. However, I get the error message:

Closing using the close option without the ability to escape may allow it to exit

Now, if localClosuresomehow escapes, I will understand this error, but it will not disappear. I even tried annotating localClosurehow @noescape(although this attribute is deprecated in Swift 3), and as per the warning, I got:

@noescape is default and deprecated

localClosure, , , ? / ?

+4
1

@escaping,

" localClosure, , , ..."

( @Hamish), Swift 3.0:

  • , , , @escaping, . @noescape Swift 3 (., , Xcode 8 Swift evolution SE-0103), , .
  • , @noescape ( , Swift 2.2), , ( Apple dev. Jordan Rose ).
  • @noescape , , ( , ) @Hamish, . SR-2969.

    "@noescape "

, localClosure @escaping, , , closure test(...) - <.

< > [†] , , .. , . >


, , , , : , , closure @escaping, / , .

func test(closure: @escaping () -> ()) -> () -> () {
    let escapingLocalClosure = { closure() }
    return escapingLocalClosure
}
+5

Source: https://habr.com/ru/post/1657916/


All Articles