So here is an example of a Tuple in Swift:
1
var player = (“Mark”, 999, true)
The ( ) lets Swift know that you are creating a Tuple. So you would add your values into the parenthesise Tuple as above and separate them with a comma.
Like an array you can return the value using the equivalent index value like so:
1 2
Player.0  // = Mark  Player.1 // = 999
Remember that the index value starts at 0 in arrays and Tuples
As you can see, this is not a very descriptive way to go about it. Another way to get this information and a very cool way I must say is to assign them names. This can be done like this:
1
var player = (name: “Mark”, score: 999, isGoldMember: true)
Now you can get them out of the Tuple like so:
1
Player.name // etc …
Lets say that you’re getting a Tuple back from a function or some other return and you want to decompose it by turning each of the parts into variables. You can do this easily by typing
1
var (name,score,isGoldMember) = player
Now you can just type put the variable name specified here, like this:
1 2 3
Name Score isGoldMember
Finally and quite possibly the coolest thing about this feature is that if you don’t want to assign a value you can just put an underscore in its place like so:
1
var (_, name, _)
There you have it. Go and play with Swift Tuples and see how awesome they are for yourselves.