Tuples are a handy Swift construct that is especially useful for functions that return multiple values. You can use it like so:
func f1() -> (Int, Int, Int) {
return (111, 222, 333)
}
var (a, b, c) = f1() //a, b, and c now stores the value 111, 222, and 333 respectively.
func f2() -> (Int, Int, Int) {
return (111, 222, 333)
}
var x = f2() //Access x.0, x.1, x.2
Or you can give the elements in the tuple a name:
func f3() -> (aa: Int, bb: Int, cc: Int) {
return (111, 222, 333)
}
var y = f3() //You can use y.aa, y.bb, y.cc (and y.0, etc still work)
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.