Swift Quick Reference
Swift essentials: constants, optionals, strings, collections, control flow, functions, closures, structs, classes and protocols.
5 sections · 27 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Constants, variables and output.
TaskCode
- Constant / variable
- Type annotation
- Convert
Optionals
Values that might be missing.
TaskCode
- Declare
- Unwrap safely
- Guard
- Default
- Optional chaining
Collections
Arrays, dictionaries and sets.
TaskCode
- Array
- Transform
- Sort
- Reverse
- Dictionary
- Loop
- Set
Control flow & functions
Logic and reuse.
TaskCode
- If / switch
- Ranges
- Function
- Closure
- Async / await
Types
Structs, classes, enums and protocols.
TaskCode
- Struct
- Class
- Enum with associated values
- Protocol
- Extension
- Errors