http://stackoverflow.com/questions/40072918/how-to-call-non-escaping-closure-inside-a-local-closure
Non-parameter closures are @escaping, by default
non-parameter closures in Swift 3.0
Given the example:
1 2 3 4 5 6 7 |
func test(closure: () -> ()) { let localClosure = { // escaping closure closure() } localClosure() // this is escaping! Thus, we must make parameter closure "closure" escaping as well } |
localClosure’s closure is @escaping which naturally means it cannot be allowed to wrap the non-escaping closure parameter “closure” of test(…).
Thus, the solution is that we may naturally mark closure as @escaping if we’d wish to process/wrap it as in the example.
1 2 3 4 |
func test(closure: @escaping () -> ()) -> () -> () { let escapingLocalClosure = { closure() } return escapingLocalClosure } |