Why is the shorthand argument name $0 returning a tuple of all parameters?

Closures § Shorthand Argument Names

Shorthand Argument Names


the number and type of the shorthand argument names will be inferred from the expected function type.

It looks like this is the expected behavior. By providing only $0 you are inferring (at least to the system) that you want a tuple.

This only seems to be a special case of using $0. For example, the following cannot be compiled.

var returnAString3: (String, String, String) -> String
returnAString3 = { return $1 }

No matter how it’s modified.

returnAString3 = { return $1.0 } // still fails.

Leave a Comment