say I have a function that has non-default parameter after default parameter like this:
func f(first:Int = 100, second:Int){}
how can I call it
On Swift 3:
func defaultParameterBefore(_ x: Int = 1, y: Int ) {}
Calling
defaultParameterBefore(2)
will raise this error
error: missing argument for parameter 'y' in call
The only exception is:
For example:
func defaultParameterBetween(_ x: Int, _ y: Bool = true, _ z: String) {
if y {
print(x)
} else
z()
}
}
// error: missing argument for parameter #3 in call
// defaultParameterWithTrailingClosure(1, { print(0) }
// Trailing closure does work, though.
func defaultParameterWithTrailingClosure(_ x: Int, y: Bool = true,
_ z: () -> Void) {
if y {
print(x)
} else {
z()
}
}
defaultParameterWithTrailingClosure(1) { print(0) }
swift version: DEVELOPMENT-SNAPSHOT-2016-04-12