Interactive tutorial
Learn Swift
A hands-on introduction, one question at a time. Modeled on the official Swift documentation and the rhythm of CS61A: a short idea, a small program, then a question about what it will do before you run it.
Follows CS61A (Fall 2026) lecture by lecture, with Swift from The Swift Programming Language (Swift 6.4).
How a lesson works
Each lesson reads like a CS61A lecture: short notes and small programs, then questions. “What would Swift print?” asks you to predict output (type Error if the program would fail); Parsons problems ask you to put shuffled lines back in order. Each lesson ends with a lab to write and run on your own machine, with solutions you can open when you are ready.
Unit 1
Building abstractions with functions
Expressions, names, and functions; control; functions that take and return functions; and recursion. CS61A’s first four weeks.
- 01Getting started
What happens between typing code and seeing output?CS61A · Welcome
Available - 02Names and functions
What does it mean to give a computation a name?CS61A · Functions
Available - 03Control
How does a program choose what to do next?CS61A · Control
Available - 04Higher-order functions
What changes when functions become values?CS61A · Higher-Order Functions
Available - 05Environments and closures
Where does a name get its value?CS61A · Environments
Available - 06Functional abstraction
What should a function promise, and what should it hide?CS61A · Abstraction · Function Examples
Available - 07Recursion
How can a function trust itself before it is finished?CS61A · Recursion
Available - 08Tree recursion
What happens when one call makes two?CS61A · Tree Recursion
Available
Unit 2
Building abstractions with data
Sequences, containers, optionals, your own types, recursive data, mutation, classes, protocols, lazy sequences, and efficiency. CS61A weeks five to nine.
- 09Sequences
What can you do with anything that comes in order?CS61A · Sequences
Available - 10Dictionaries, sets, and tuples
Which container fits which question?CS61A · Containers
Available - 11Optionals
How do you represent “there might be nothing here”?CS61A · Containers (Swift-specific)
Available - 12Structures and enumerations
How do you make invalid states impossible to write?CS61A · Objects
Available - 13Linked lists and trees
How can a type contain itself?CS61A · Linked Lists · Trees
Available - 14Mutation and value semantics
When does changing one thing change another?CS61A · Mutation
Available - 15Classes and inheritance
When is sharing an object what you want?CS61A · Classes · Inheritance
Available - 16Protocols and generics
How do you write code for types that do not exist yet?CS61A · Object Examples (interfaces)
Available - 17Iterators and lazy sequences
Can you work with a sequence that never ends?CS61A · Lazy Evaluation · Generators
Available - 18Efficiency and memoization
Why does the same answer sometimes take so much longer?CS61A · Efficiency
Available
Unit 3
Programs that meet the world
Algebraic data types, interpreters, errors, concurrency, testing, and packages. CS61A’s last weeks, with Swift in place of Gleam and SQL.
- 19Algebraic data types and pattern matching
What if the compiler checked every case for you?CS61A · Functional Programming · Algebraic Data Types · Immutable Data
Planned - 20Writing an interpreter
What does it take to run a language?CS61A · Interpreters
Planned - 21Error handling
What should a function do when it cannot do its job?CS61A · Debugging
Planned - 22Concurrency with async and await
How do you wait without stopping everything?CS61A · Browsers · Applications
Planned - 23Testing
How do you know your program is right?CS61A · Software Testing · Software Tracing
Planned - 24Building a Swift package
How does code become something other people can use?CS61A · Applications · Conclusion
Planned