MasterOnce
HomeBlogHow-To
3 min readJan 27, 2026
Swift

How to Use Dictionaries

Store key-value data with fast lookups.

Steps

  1. Paste the code into a Swift file or playground.
  2. Run it once to verify the output.
  3. 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.