Tuples
Using tuples (pronounced “TWO-pulls” or “TUH-pulls”) is a way to group multiple values into one. Think of associated values. Here is an example with URL settings:
let purchaseEndpoint = ("buy","POST","/buy/")
This tuple has a String
, a String
, and a String
. This tuple is considered to be of type (String
, String
, String
). You can put as many values as you want in a tuple, but you should use them for what they are meant for. You can mix types in tuples as well, like this:
let purchaseEndpoint = ("buy","POST","/buy/",true)
This tuple has a String
, a String
, a String
, and a Bool
. You are mixing types here, and this tuple is considered to be of type (String
, String
, String
, Bool
Get Learning Swift™ Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.