Search code examples
iosswiftprogramming-languages

How to call the following function in swift without specifying a value for the optional parameter?


In swift it is allowed to have parameters in functions with default values, and it is allowed to have parameters without external names. But, what happens when I combine them? For example, in the following code:

func foo (a: Int, b: Int = 0, _ c: Int) {
    print(a + b + c)
}

Is there any way of call the function foo without specifying a value for parameter b?


Solution

  • No you can't. That's why Apple recommends in the Swift book to place parameters with default values at the end of the parameters list: excerpt from Swift book