Swift Language Decomposing into individual variables


Example

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"