3 min readJan 27, 2026
SwiftHow to Use Dictionaries
Store key-value data with fast lookups.
Steps
- Paste the code into a Swift file or playground.
- Run it once to verify the output.
- Adjust the inputs to match your use case.
Copy and paste
import Foundation
var ages = ["Ava": 28, "Liam": 31]
ages["Noah"] = 25
if let age = ages["Ava"] {
print("Ava is (age)")
}Notes
- Keep functions small and focused for reuse.
- Prefer safe APIs like optionals and guards.
