Swift: mixing default values and variadic parameters.


As of Xcode 7 beta 6, Swift no longer requires variadic parameters to be last in the function definition. Also argument labels are no longer required when combined with parameters with default values. So this all works fine now:

The rest of this post is deprecated.


In SwiftShell I would like to run a shell command with varying numbers of arguments and have some parameters with default values, like this:

which would be defined like so:

Variadic parameters must be last in the definition, but labelled parameters can go after them when calling:

This however does not work:

It seems parameters with default values are no longer optional when used together with variadic parameters.

Well not quite:

It works, but run("cmd", "arg1", "arg2") is inarguably much prettier than run2("cmd", args: "arg1", "arg2").

So to sum up: if you’re going to have both parameters with default values and variadic parameters the variadic parameters must have an argument label.