Collections
Dictionary Lookup
Dictionaries map keys to values so code can look up a value by name.
Read by key
dictionary_lookup.swift
let city =
let temperatures = ["Austin": 72, "Denver": 55, "Seattle": 63]
let current = temperatures[city]!
let warmEnough = current >= 65
print("city=\(city)")
print("temperature=\(current)")
print("warmEnough=\(warmEnough)")
let city =
let temperatures = ["Austin": 72, "Denver": 55, "Seattle": 63]
let current = temperatures[city]!
let warmEnough = current >= 65
print("city=\(city)")
print("temperature=\(current)")
print("warmEnough=\(warmEnough)")
let city =
let temperatures = ["Austin": 72, "Denver": 55, "Seattle": 63]
let current = temperatures[city]!
let warmEnough = current >= 65
print("city=\(city)")
print("temperature=\(current)")
print("warmEnough=\(warmEnough)")
dictionaries
A dictionary lookup uses a key. When the key is known to exist, unwrapping the result gives the stored value for later calculations.