8/26/2018 - 6:53 PM


// Collections and Control Flow

// Array

var todo: [String] = ["Finish collection course", "Buy groceries", "Respond to emails"]

// Add new item to end of array using append method
todo.append("Pick up dry cleaning")

// Concatenating two arrays
[1, 2, 3] + [4]

//Concatenate array containing string literal to todo
todo = todo + ["Order book online"]
// Performing the same operation using the unary addition operator
todo += ["Order book online"]

// Immutable Arrays

let secondTaskList = ["Mow the lawn"]

// Reading from Arrays

let firstTask = todo[0]
let thirdTask = todo[2]

// Modifying Existing Values in an Array
// (Mutating an array)

todo[4] = "Brush teeth"
todo[0] = "Watch Treehouse content"

// Insert Using Indexes
todo.insert("Watch TV", at: 2)

//  Removing Items from Arrays

todo.remove(at: 1)


// Dictionaries

 Airport Code (Key)     Airport Name (Value)
 LGA                    La Guardia
 LHR                    Heathrow
 CDG                    Charles de Gaule
 HKG                    Hong Kong International
 DXB                    Dubai Intetnational

var airportCodes: [String: String] =
["LGA": "La Guardia",
 "LHR": "Heathrow",
 "CDG": "Charles de Gaule",
 "HKG": "Hong Kong International",
 "DXB": "Dubai International"]

// Reading from a dcitonary


// Inserting Key Value Pairs

airportCodes["SYD"] = "Sydney Airport"

// Updating Key Value Pairs

airportCodes["LGA"] = "La Guardia International Airport"

airportCodes.updateValue("Dublin Airport", forKey: "DUB")

// Removing Key Value Pairs

airportCodes["DXB"] = nil

airportCodes.removeValue(forKey: "CDG")

// Dealing with Non Existent Data

let newYorkAirport = airportCodes["LGA"]
let orlandoAirport = airportCodes["MCO"]