Swift 5.1: Tuples Cheat Sheet

// Group multiple values into
// a single compound value
let httpError = (503, “Server Error")
// Decomposing a tuple's contents
let (code, reason) = httpError
// Another way to decompose
let codeByIndex = httpError.0
let reasonByIndex = httpError.1
// Ignoring parts of the tuple using _
let (_, justTheReason) = httpError

Leave a Reply

Your email address will not be published. Required fields are marked *