Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Variadic arguments

We can include an arbitrary number of arguments (of a single type) using the following variadic parameter syntax:

func introduceNumbers(string: String, numbers: Int...) 
{
for number in numbers
{
print(string, number)
}
}

We can now call this function with as many Int arguments as we need to:

introduceNumbers(string: "This is a", numbers: 1) 
introduceNumbers(string: "This is a", numbers: 1,2,3)
Variadic arguments once needed to be the last argument in the parameter list, but this is no longer the case. However, this is another one to watch out for when browsing older documentation of posts on the web.