Decomposing into individual variables

suggest change

Tuples can be decomposed into individual variables with the following syntax:

let myTuple = (name: "Some Name", age: 26)
let (first, second) = myTuple

print(first) // "Some Name"
print(second)  // 26

This syntax can be used regardless of if the tuple has unnamed properties:

let unnamedTuple = ("uno", "dos")
let (one, two) = unnamedTuple
print(one) // "uno"
print(two) // "dos"

Specific properties can be ignored by using underscore (\_):

let longTuple = ("ichi", "ni", "san")
let (_, _, third) = longTuple
print(third) // "san"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents