O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tuples

Tuples group multiple values into a single compound value. Unlike arrays and dictionaries, the values in a tuple do not have to be of the same type. While tuples are included in this chapter about collections, they actually behave more like a custom type than a collection.

The following example shows how to define a tuple:

var team = ("Boston", "Red Sox", 97, 65, 59.9) 

In the preceding example, an unnamed tuple was created that contains two strings, two integers, and one double. The values of the tuple can be decomposed into a set of variables, as shown in the following example:

var team = ("Boston", "Red Sox", 97, 65, 59.9)  
var (city, name, wins, loses, percent) = team 

In the preceding code, the city variable will contain Boston ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required