The above function is an example of multiple input parameters. It does the addition of two numbers. number1 and number are arguments of type Int and it returns a value of type int. And a function without parameter looks like this.

func sum() -> (Int) {

return 10 + 5

}

The above function is an example of multiple input parameters. It does the addition of two numbers. number1 and number are arguments of type Int and it returns a value of type int. And a function without parameter looks like this. Swift function can also have multiple return values.

Define external parameter name

func sum(addNumber1 number1:Int, withNumber2 number2: Int) -> (Int) {

return number1 + number2

}

println(sum(addNumber1: 10, withNumber2: 20))

Define addNumber1 and withNumber are external parameter names for two parameters. Use # to tell local and external parameter name are same.

func sum(#number1:Int, #withnumber2: Int) -> (Int) {

return number1 + withnumber2

}

println(sum(number1: 10, withnumber2: 20))

Function with default parameter value

func sum(number1:Int, withnumber2: Int = 20) -> (Int) {

return number1 + withnumber2

}

println(sum(10))

The above function has default value for the second parameter.

Variadic Parameters

A function with variadic parameters can accept zero or more values. Maximum of one parameter is allowed in a function and it is always last in the list.

Variable and inout parameters

Variable parameters in a function are indicated by var keyword and the scope is available only within the function. If you want to access the modified variable value outside the function then you specify them as inout parameter. And prefix with & while passing the parameter in the function call.