I have a function with a completion handler, returning one parameter or more.
In a client, when executing a completion handler, I'd like to have an unowned
reference to self
, as well as having access to the parameter passed.
Here is the Playground example illustrating the issue and the goal I'm trying to achieve.
import UIKit
struct Struct {
func function(completion: (String) -> ()) {
completion("Boom!")
}
func noArgumentsFunction(completion: () -> Void) {
completion()
}
}
class Class2 {
func execute() {
Struct().noArgumentsFunction { [unowned self] in
//...
}
Struct().function { (string) in // Need [unowned self] here
//...
}
}
}
As I said in my comment
Capture list and closure parameters that should be the order in closures more info from Apple Documentation