SR-2552 reports that @escaping does not recognize a function type alias. therefore @escaping attribute only applies to function types error @escaping attribute only applies to function types . You can get around this by expanding the type of the function in the function signature:
typealias Action = () -> () var action: Action? = { } func doStuff(stuff: String, completion: (@escaping ()->())?) { print(stuff) action = completion completion?() } func doStuffAgain() { print("again") action?() } doStuff(stuff: "do stuff") { print("swift 3!") } doStuffAgain()
EDIT 1 :
I was actually under beta version of xcode 8 where the error SR-2552 has not yet been resolved. correcting this error, introduced a new one (the one you encountered) that is still open. see SR-2444 .
The @Michael Ilseman workaround indicated that a workaround is to remove the @escaping attribute from an optional function type that saves the function as an escape one .
func doStuff(stuff: String, completion: Action?) {...}
EDIT 2 :
SR-2444 was closed, specifically indicating that closing in position parameters cannot be avoided, and it is necessary that they be marked with @escaping to make them escape, but optional parameters are implicitly avoided, since ((Int)->())? is synonymous with Optional<(Int)->()> , additional closures screen.
Jans Sep 21 '16 at 14:21 2016-09-21 14:21
source share