Thanks. I asked a question about tuple splatting a while back. I think below is an example of tuple splatting:
func f(_ c: ((Int, Int)) -> Void) {
let data = (1, 2)
c(data)
}
func test1() {
f { x, y in
print("x: \(x), y: \(y)")
}
}
But the example in my current question is different. It essentially does the following:
func f(_ c: ((Int, Int)) -> Void) {
let data = (1, 2)
c(data)
}
func test2() {
f { (x, y) in // Note it's "(x, y)", not "x, y"!
print("x: \(x), y: \(y)")
}
}
It's not obvious to me why this is tuple splatting, unless (x, y)
is equivalent to x, y
in above code. I for one don't think they are equivalent. That's why I thought it's tuple pattern.