Tsallaka zuwa abun ciki
Justice Tech School

Swift Dictionaries

A dictionary maps unique keys to values. Looking up a key returns an optional. Sets hold unique values.

Example
var ages = ["Ada": 21, "Tunde": 30]
ages["Zed"] = 25
print(ages["Ada"] ?? 0)
for (k, v) in ages.sorted(by: { $0.key < $1.key }) { print(k, v) }
let s: Set = [1, 2, 2, 3]
print(s.count)

Exercise

Missing key result.

ages["x"] is 

Quiz Test

What does a missing key return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.