I have a handler defined this way:
var handler: (String, (Bool) -> Void) -> Void
I am passing this in:
handler: ((String) -> Void)
{ a in
print(a)
}
I get this error and I don't understand how to fix it.
Type '(String) -> Void' has no member 'init'
When I tried this way I got the same error but I don't think it is correct as the handler passes in another closure with the boolean.
handler: (String, (Bool) -> Void) -> Void)
{ a in
print(a)
}
CodePudding user response:
The issue there is that the closure expects two parameters:
var handler: (String, (Bool) -> Void) -> Void = { _,_ in }
handler = { a, b in
print(a)
b(false)
}
handler("a") { bool in print(bool) }
This will print:
a
false