Free through lesson 3

Swift for Beginners

From setting up your environment through variables, control flow, collections, optionals, functions and closures, structs and classes, protocols, error handling and async/await. Fifty lessons that take you to the point where you can read and write Swift without Xcode and assemble a task manager that saves to JSON. Every piece of code and result shown was produced by actually running Apple Swift 6.3.3.

Curriculum

The 50 lessons are grouped into seven chapters. Working through them in order is the best way, but you are welcome to dip into whatever interests you. Note: this cannot run inside the browser, so try it with your own swift command (Xcode Command Line Tools).

Chapter 1 — Getting started (lessons 1–8)

You get to grips with how Swift runs and get to the point of executing it yourself without Xcode. You cover variables, numbers, strings and standard input, and how to read compiler errors.

Chapter 2 — Control flow (lessons 9–15)

You cover conditionals and repetition: pattern matching with if and switch, for-in and ranges, while, break and continue. You finish by assembling a number-guessing game.

Chapter 3 — Collections and optionals (lessons 16–24)

You gather values with Array, Dictionary, Set and tuples, and transform them with map, filter and reduce. Optionals and guard — the crux of Swift — are covered here too, and you finish by aggregating sales data.

Chapter 4 — Functions and closures (lessons 25–32)

You split work up by naming it, and learn to pass functions around as values. Argument labels, inout, closures, higher-order functions, generics and recursion, and on to refactoring.

Chapter 5 — Structs and classes (lessons 33–38)

You create your own data types. The difference between struct and class (value types versus reference types), mutating, initialisers, inheritance, computed properties and observers.

Chapter 6 — Enums and protocols (lessons 39–42)

You turn the states something can be in into a type using enums with associated values, and gather behaviour with protocols and extensions. You finish by building an inventory system from structs and protocols.

Chapter 7 — Practice and beyond (lessons 43–50)

throws, Result, file I/O, Codable, Swift Package Manager and async/await. You finish a task manager that saves to JSON, and see what to learn next.

Once you have finished all 50 lessons, look at Rust for Beginners, which leans towards safety in much the same way, or make types your weapon in TypeScript for Beginners. Membership unlocks every course.