Skip to content
academia.sh

Course Beginner

The Swift Language

Published Updated

By the end of this course

Start course

01

Language Basics

Swift's design goals, constants and variables, type inference, basic types, the string and character model, operators, control flow with pattern-matching switch, functions with argument labels, and closures with capture lists.

  1. 01 Swift's Design Goals Ties Swift's three goals — safety, expressiveness, performance — to one measurement axis: when is this expression evaluated? Splits eight expressions into four moments.
  2. 02 Constants and Variables Measures `let` and `var` together with type inference, explicit type annotation and the moment of assignment: is a constant evaluated immediately, and is an assignment evaluated every time?
  3. 03 Basic Types Introduces the `Int`, `Double`, `Bool` and `String` types; measures that conversion is explicit and that a conversion expression is evaluated immediately.
  4. 04 String Operations Measures the character and byte counts of a `String` value, indexing and interpolation: an interpolated expression is rebuilt on every use.
  5. 05 Operators Introduces arithmetic, comparison and range operators; measures that the right-hand side of `||`, `&&` and the ternary operator may never be evaluated.
  6. 06 Control Flow Introduces conditions, loops and the pattern-matching `switch` statement; measures that `where` conditions after the first match are never evaluated.
  7. 07 Functions Introduces argument labels, default values, multiple returns through a tuple and the `inout` parameter; measures that a default argument expression is evaluated on every call.
  8. 08 Closures Introduces closure syntax, the `$0` shorthand, the trailing closure and the `sorted(by:)` call; measures that a capture list is evaluated once, when the closure is created.

02

The Type System

Optionals as the expression of absence in the type, and safe unwrapping; value and reference semantics with structures and classes; enumerations; stored, computed and observed properties; protocols, extensions, generics, error handling and access control.

  1. 01 Optionals Measuring how absence is expressed in the type, why a transforming closure never runs on nil, and where absence stops in nested layers.
  2. 02 Unwrapping Optionals Measuring when the right-hand side of if let and guard let, a ?? chain and optional chaining are evaluated.
  3. 03 Structures and Classes Measuring copying on assignment for structures, sharing for classes, when a default value is built, and why a copy appears at the first mutation.
  4. 04 Enumerations Measuring when a raw value and an associated value are set up, how pattern matching opens them, and why a computed property runs on every read.
  5. 05 Properties Measuring when stored, computed and observed properties, lazy properties and static let values are set up.
  6. 06 Protocols Measures when a value that fulfills a protocol requirement is evaluated: a default implementation runs on every call, but the conforming type decides the moment.
  7. 07 Extensions Measures adding methods, computed properties and protocol conformance to an existing type from the outside; shows that a stored property cannot be added, and the type-level exception.
  8. 08 Generics Applies one body to many types with type parameters and constraints; measures the transformer of a lazy sequence on every access and that of an eager map immediately.
  9. 09 Error Handling Measures that nothing after the `throw` line in the body of a throwing function ever runs, while a `defer` block runs on every exit.
  10. 10 Access Control Measures that making a cache `private` does not change the moment of evaluation, and that access control is decided at compile time.

03

Memory and Advanced Features

Automatic reference counting, breaking retain cycles with strong, weak and unowned references, capturing in closures, property wrappers, result builders, and isolation under strict concurrency checking.

  1. 01 Automatic Reference Counting Measures the point at which deinit runs once the last strong reference is released along four release paths, and shows that a second reference postpones that moment.
  2. 02 Strong, Weak and Unowned References Measures that deinit never runs when two classes hold each other strongly, that weak and unowned break the cycle, and that an unowned reference cannot be read once its object is gone.
  3. 03 Capturing in Closures Measures that a closure stored in an object's own property blocks deinit when it captures self, that a weak self capture list resolves it, and that a capture list is evaluated once when the closure is created.
  4. 04 Property Wrappers Measures that the wrappedValue getter of a property wrapper runs on every access, that the initial value is set up once, and that a cached wrapper turns the moment into first use.
  5. 05 Result Builders Writes a result builder of its own and measures that expressions in an unchosen if or else branch are never evaluated, that a for loop evaluates every element, and that the branch is chosen at run time and not at compile time.
  6. 06 Concurrency Safety Measures that the lazy property of an actor is set up once under concurrent reads and that an async let whose result is never awaited is still evaluated; covers the Sendable and @MainActor boundaries and closes the course.

Final exam

The Swift Language — Final Exam

In preparation

This course's question bank is not complete yet. The exam opens here automatically once enough questions are added.

Start typing to search.

↑↓ ↵ Esc navigate · open · close