passing unknown number of arguments in a function

swift

Solution

Swift `Variadic Parameters` accepts zero or more parameters of a specified type. Syntax of variadic parameters is, insert three period characters `(...)` after the parameter’s type name.

func anyNumberOfTextField(_ textField: UITextField...) {

}

Now you can pass any number of textField.

anyNumberField(UITextField(),UITextField(), UITextField(), UITextField())

Note: A function may have at most one variadic parameter.

For more info check this Swift Functions

There is another way you can do that is called `Array Parameter`. There are some pros and cons of these two methods. You will find the difference here link.

Problem

In my current project, I had to implement multiple functions to handle the different number of `UITextField` in multiple screens of my application. I guess it would be more efficient if I can implement one function that can take any number of `UITextField`. Is it possible to implement this surd of functions on swift 3?

Original source

Related problems