Swift - Function Parameter Default Value


You can create functions whose parameters have default values.

You can call these functions and omit certain parameters.

Those parameters will use the values provided in the function's definition:


func multiplyNumbers2(firstNumber: Int, multiplier: Int = 2) -> Int { 
    return firstNumber * multiplier; 
// Parameters with default values can be omitted 
var a = multiplyNumbers2(firstNumber: 2) // 4 
print(a)//from   w ww  . ja v a 2 s .  co  m


Related Topic