'why does swift closure complain there is no init

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)
                }

Error message and code screenshot



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1