In Swift, it seems possible to create a variational function with the vararg parameter, which is not the last parameter of the function.
I created the following function:
func test1(_ array: String..., _ tag: String){
print("[\(tag)] array: \(array)")
}
Since it is possible to define the vararg parameter without making it the last parameter, I suspected that the Swift compiler would simply take the last argument and make it the argument for the second parameter.
test1("Hello", "World", "Greeting")
But this does not work, which is not too strange.
This also does not work:
let arrayOfStrings: [String] = ["Hello", "World"]
test1(arrayOfStrings, "Greeting")
Obviously, the label is used for the second parameter.
func test2(_ array: String..., tag: String){
print("[\(tag)] array: \(array)")
}
But I decided to make another attempt. This compilation of the function does not generate a warning, but can I use it?
func test3(_ array: String..., _ tag: Int){
print("[\(tag)] array: \(array)")
}
test3("Hello", "World", 1)
Is it possible to call the first method or the third method without pointing the second parameter to the label?
: ? ? , , , .