Tuples allow you to 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:
name.0
Or you can access items using their names:
name.first
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.
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.