Skip to content

Instantly share code, notes, and snippets.

@KDawg
Created August 30, 2019 16:22
Show Gist options
  • Save KDawg/8a589c30d45e3e87b02c7d1dccc7809f to your computer and use it in GitHub Desktop.
Save KDawg/8a589c30d45e3e87b02c7d1dccc7809f to your computer and use it in GitHub Desktop.
This is an example of the Tuple type in Swift programming language
// This is an example of the Tuple type in Swift programming language
// I use this type of data to easily return multiple values from a function call
// SEE: https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID329
let t = (200, "OK", "HTTP 200 is a successful return code. The request has succeeded.")
print(t) // shows the entire tuple
print(t.0) // shows 200
print(t.1) // shows "OK"
print(t.2) // shows the longer message
print(t.3) // will be an error
let (a,b,c) = t // destructures the tuple into 3 separate variables
print(a) // shows 200
print(b) // shows "OK"
print(c) // shows the longer message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment