Swift
Comprehensive Swift reference for iOS and macOS development
Table of Contents
Getting Started
Swift basics and setup
Variables & Constants
Declaration and initialization
Basic Types
Swift fundamental data types
Optionals
Handling nil values safely
Optional Basics
Declaration and unwrapping
Collections
Arrays, Sets, and Dictionaries
Arrays
Ordered collections of values
Dictionaries
Key-value pair collections
Functions & Closures
Function definitions and closures
Functions
Function declaration and parameters
Closures
Anonymous functions and capturing
Structs & Classes
Value and reference types
Structs
Value types with properties and methods
Classes
Reference types with inheritance
Enums
Enumerations with associated values
Basic Enums
Simple and raw value enumerations
Associated Values
Enums with different value types
Protocols
Protocol definitions and conformance
Protocol Basics
Defining and adopting protocols
Error Handling
Throwing and catching errors
Error Basics
Defining and throwing errors
Concurrency
Async/await and actors
Async/Await
Modern Swift concurrency
Actors
Thread-safe reference types
Extensions
Extending existing types with new functionality
Type Extensions
Adding functionality to existing types
Conditional Extensions
Extensions with generic constraints
Generics (Advanced)
Generic programming and type constraints
Generic Constraints
Advanced generic type relationships
Memory Management
ARC, weak/unowned references, and memory optimization
Reference Cycles
Breaking retain cycles with weak and unowned
Access Control
Controlling visibility and access to code
Access Levels
Five levels of access control
Type Casting
Type checking, casting, and Any/AnyObject
Type Checking & Casting
is, as, as?, as! operators
Property Wrappers
Encapsulating property storage logic
Creating Property Wrappers
Custom property wrapper implementation
Operators
Custom operators and operator overloading
Custom Operators
Defining and implementing custom operators
Attributes
Swift attributes for compile-time configuration
Common Attributes
Built-in Swift attributes
Initialization
Initialization rules and patterns
Initialization Patterns
Designated, convenience, and failable initializers
Subscripts
Custom subscript syntax for types
Subscript Implementation
Adding subscript access to custom types
Result Builders
Building DSLs with result builders
Result Builder Basics
Creating domain-specific languages