Tuples allow you store several values together in a single value. That might sound like arrays, but tuples are different:
Tuples are created by placing multiple items into parentheses, like this:
var name = (first: "Taylor", last: "Swift")
You then access items using numerical positions starting from 0:
Or you can access items using their names:
Remember, you can change the values inside a tuple after you create it, but not the types of values. So, if you tried to change
name to be
(first: "Justin", age: 25) you would get an error.
UPGRADE YOUR SWIFT Hacking with Swift Live is a new iOS conference taking place in the UK this July, with all profits going to charity. Come and learn the major new APIs announced at WWDC19 with sessions and hands-on tutorials – click here to learn more!