Putting It All Together

Next, you will create a little program from all the massive amounts of knowledge you have acquired thus far. Enter the code in Listing 2.1.

Listing 2.1 A Complete Example

import Foundationlet city = "Boston"let trainName = "the Red Line"var subwayStops = [    // Stop name and busyness on a scale of 1-10    ("Harvard Square", 6),    ("Kendall / MIT", 5),    ("Central Square", 7),    ("Charles MGH", 4),    ("Park Street", 10)]var passengers = 0for i in 0..<subwayStops.count {    var (stopName, busyness) = subwayStops[i]    // New passengers boarding the train    var board:Int    switch (busyness) {    case 1...4: board = 15    case 5...7: board = 30    case 7..<9: board = 45    case 10: board ...

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.