coderef

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.

  • Constant / variable
  • Type annotation
  • Print
  • Convert

Optionals

Values that might be missing.

  • Declare
  • Unwrap safely
  • Guard
  • Default
  • Optional chaining

Collections

Arrays, dictionaries and sets.

  • Array
  • Transform
  • Sort
  • Reverse
  • Dictionary
  • Loop
  • Set

Control flow & functions

Logic and reuse.

  • If / switch
  • Ranges
  • Function
  • Closure
  • Async / await

Types

Structs, classes, enums and protocols.

  • Struct
  • Class
  • Enum with associated values
  • Protocol
  • Extension
  • Errors

← All quick references