9.15 Shorthand Argument Names
A useful technique for simplifying closures involves using shorthand argument names. This allows the parameter names and “in” keyword to be omitted from the declaration and the arguments to be referenced as $0, $1, $2 etc.
Consider, for example, a closure expression designed to concatenate two strings:
let join = { (string1: String, string2: String) -> String in
string1 + string2
}
Using shorthand argument names, this declaration can be simplified as follows:
let join: (String, String) -> String = {
$0 + $1
}
Note that the type declaration ((String, String) -> String) has been moved to the left of the assignment operator since the closure expression no longer defines the argument or return types.