I don’t think you can do what you want. To simplify your example a bit, you can do this:
typealias NamedCheck = (number: Int) -> Bool let f: NamedCheck = { $0 < 5 } f(number: 1) NamedFunction(f) NamedFunction( { $0 < 5 } as NamedCheck)
But you can't do what you want to rely on the arg tuple called number to refer to it inside the closure without providing it as part of the closure:
// compiler error, no idea what "number" is let g: NamedCheck = { number < 5 }
Keep in mind that you can name a parameter without specifying its type (which is inferred from type g ):
let g: NamedCheck = { number in number < 5 }
but also you can name it as you want:
let h: NamedCheck = { whatevs in whatevs < 5 } NamedFunction(h)
Here I think this is happening (this is partly a guess). Remember how functions can have names of external and internal arguments:
func takesNamedArgument(
Or to write this longhand:
func takesNamedArgument(namedArg namedArg: Int) { etc... }
But you can also specify as the second, internal, name that you like:
func takesNamedArgument(namedArg whatevs: Int) { etc... }
I think this is what happens with the closure with the named tuples. The "external" name is "number", but you must also give it the "internal" name, which you must use in the body of the function. You cannot use an external argument inside your function. In the case of closure expressions, if you do not specify an internal name, you can use $0 , etc., but you can’t just skip it, nothing more, you can skip the internal name altogether and just rely on the external name when defining a regular function .
I was hoping I could prove this theory as follows:
let f = { (
as a result, f is of type (a: Int, b: Int)->Bool) . This compiles, like:
let g = { (number1 a: Int, number2 b: Int)->Bool in a < b }
but it doesn’t look like the external argument names represent type f or g .