Skip to content

Swift Programming Textbook

A free, self-paced textbook in 7 chapters. Read a chapter, then drill it with the 50 companion flashcards using spaced repetition.

7 chapters · 50 cards · Updated

Chapters

  1. 1Optionals and Safe Unwrapping

    An Optional in Swift is a type that can hold either a value or the absence of a value, represented by nil. It is declared by appending a question mark to the type, as in var name:...

  2. 2Protocols and Extensions

    A Protocol in Swift defines a blueprint of methods, properties, and other requirements that conforming types must implement. Classes, structs, and enums can all conform to a protoc...

  3. 3Closures and Functional Patterns

    A closure in Swift is a self-contained block of functionality that can be passed around and used throughout the code. Closures have a syntax that resembles a function without a nam...

  4. 4Types: Structs, Classes, and Enums

    Swift has two fundamental categories of types based on how they are stored and passed. Value types, which include structs, enums, and tuples, are copied when assigned or passed int...

  5. 5Generics and Type Abstraction

    Generics enable developers to write flexible, reusable functions and types that work with any type. Instead of duplicating logic for each type, a generic placeholder like T is used...

  6. 6Error Handling and Control Flow

    Swift uses a do-try-catch model for error handling that integrates well with the type system. Functions that can fail are marked with the throws keyword, and callers must explicitl...

  7. 7Memory Management, Properties, and Advanced Features

    Memory management in Swift for class instances is handled by Automatic Reference Counting, or ARC, which tracks the number of strong references to each instance and deallocates the...

← Back to the Swift Programming deck