Dictionary
Key-value pairs.
Syntax
var m = ["k": v] m["k"]
Description
Stores key-value pairs. m["k"] returns an Optional; use ! for a guaranteed value or ?? for a default.
Example
Loading editor…
Expected output
Alex 2
When to use?
Holding object properties; JSON data.
Common mistakes
- ⚠️ If m["k"] is printed directly, Optional(...) appears; use ! or ??.