Skip to content

Instantly share code, notes, and snippets.

@kostiakoval
Last active August 29, 2015 14:16
Show Gist options
  • Save kostiakoval/f60595f3b56cad6c0a9e to your computer and use it in GitHub Desktop.
Save kostiakoval/f60595f3b56cad6c0a9e to your computer and use it in GitHub Desktop.
Tuples as function arguments, part 3
//Default value
func sum4(x: Int, y: Int, maybe: Int = 1) -> Int {
return x + y + maybe
}
let params4 = (1, 5, 1)
let params4_1 = (1, 5, maybe: 1)
sum4(1, 5, maybe: 1)
sum4(1, 5)
sum4(params4) //Fails
sum4(params4_1) //Fails
// Optional
func sum5(x: Int, y: Int, maybe: Int?) -> Int {
return x + y + (maybe ?? 0)
}
let params5 = (1, 5, 3)
let params5_1 = (1, 5, Optional<Int>.None)
sum5(params5) //Fails, 3 is not optional
sum5(params5_1)
struct A {
func sum(x: Int, y: Int) { }
static func sum1(x: Int, y: Int) { }
}
let aParams = (1, y:4)
let a = A()
a.sum(aParams)
A.sum1(aParams)
// inline Tuples
a.sum((1, y:1)) // Fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment