Swift Cheat Sheet
|
This section documents the Swift 6 language mode as shipped by Swift 6.3, as published in The Swift Programming Language at docs.swift.org, which is the reference these pages are written and verified against. 6.4-beta-only features are always flagged as such — never presented as baseline. This content was generated with the assistance of AI and should be verified against docs.swift.org before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
A single-page, colour-coded summary of the Swift essentials — let/var and the basic types, optional
binding (if let, guard let, ??, ?., forced unwrapping), string literals and interpolation, Array/
Set/Dictionary one-liners and the higher-order functions (map, filter, reduce, compactMap), control
flow (for, while, if/switch as expressions, guard, defer, pattern matching), functions and closures
(argument labels, inout, trailing closures, $0, capture lists), enum syntax with associated and raw values,
a struct-versus-class comparison table, properties (computed, lazy, observers, wrappers), initializers
(designated, convenience, failable, two-phase), protocols and extensions, generics with some/any, error
handling (throws, do/catch, try?, typed throws, Result), ARC (weak/unowned), the access-level
table, concurrency (async/await, Task, task groups, actor, @MainActor, Sendable), regular
expressions and key-path one-liners, macros, an attributes quick list, the Package.swift skeleton, Swift
Testing/XCTest snippets, and the swift/swiftc command lines — handy for quick memorization or as a
printable desk reference.
Features introduced in Swift 6.1, 6.2 and 6.3 are marked with their version on the sheet, so it doubles as an upgrade checklist; 6.4-beta-only material is marked as such.
For the full explanation, every option, and additional examples, see the dedicated pages:
Getting started — Getting Started and Lexical Structure and Style.
Language fundamentals — Basics: Constants, Variables and Types, Optionals, Operators, Strings and Characters, Collections, Control Flow, Pattern Matching, Functions, and Closures.
Types and object modelling — Enumerations, Structures and Classes, Properties, Methods and Subscripts, Inheritance, Initialization and Deinitialization, Extensions and Nested Types, Protocols, Generics, Opaque and Boxed Protocol Types, and Type Casting and Reflection.
Errors, safety and memory — Error Handling, Automatic Reference Counting, Memory Safety and Unsafe Pointers, and Access Control.
Concurrency — Async/Await and Tasks, Actors, Isolation and Sendable, and Dispatch and Legacy Concurrency.
Advanced language features — Advanced Operators, Result Builders, Key Paths and Dynamic Member Lookup, Regular Expressions, Macros, Attributes and Compiler Control, and Functional Programming.
Standard library and Foundation — Standard Library Overview, Codable and Serialization, and Foundation Essentials.
Interoperability — Interoperability with C, Objective-C and C++.
Tooling and testing — Swift Package Manager, Build and Tooling, and Testing.