Interactive tutorial
Learn Swift
A hands-on introduction, one question at a time. Modeled on the official Swift documentation and the rhythm of CS61A and CS61B: a short idea, a small program, then a question about what it will do before you run it.
Follows CS61A (Fall 2026) and CS61B (Spring 2026) lecture by lecture, with Swift from The Swift Programming Language (Swift 6.4) and the official documentation.
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
Discussions, homework, and projects
- Discussion 0Getting startedGetting startedAvailable
- Discussion 1Control and environment diagramsNames and functions · ControlAvailable
- Homework 1Functions and controlNames and functions · ControlAvailable
- Discussion 2Higher-order functionsHigher-order functions · Environments and closuresAvailable
- Homework 2Higher-order functionsHigher-order functions · Environments and closures · Functional abstractionAvailable
- Project 1HogNames and functions · Control · Higher-order functions · Environments and closures · Functional abstractionAvailable
- Discussion 3RecursionRecursionAvailable
- Discussion 4Tree recursionTree recursionAvailable
- Homework 3RecursionRecursion · Tree recursionAvailable
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
Discussions, homework, and projects
- Homework 4Sequences and containersSequences · Dictionaries, sets, and tuples · OptionalsAvailable
- Project 2CatsSequences · Dictionaries, sets, and tuples · Optionals · Higher-order functions · Tree recursion · Efficiency and memoizationAvailable
- Discussion 5TreesLinked lists and treesAvailable
- Homework 5Recursive data and mutationStructures and enumerations · Linked lists and trees · Mutation and value semanticsAvailable
- Discussion 6Objects and classesStructures and enumerations · Mutation and value semantics · Classes and inheritanceAvailable
- Homework 6Classes and interfacesClasses and inheritance · Protocols and genericsAvailable
- Project 3Ants vs. SomeBeesStructures and enumerations · Classes and inheritance · Protocols and genericsAvailable
- Discussion 7Iterators and efficiencyIterators and lazy sequences · Efficiency and memoizationAvailable
- Homework 7Lazy sequences and efficiencyIterators and lazy sequences · Efficiency and memoizationAvailable
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
Available - 20Writing an interpreter
What does it take to run a language?CS61A · Interpreters
Available - 21Error handling
What should a function do when it cannot do its job?CS61A · Debugging
Available - 22Concurrency with async and await
How do you wait without stopping everything?CS61A · Browsers · Applications
Available - 23Testing
How do you know your program is right?CS61A · Software Testing · Software Tracing
Available - 24Building a Swift package
How does code become something other people can use?CS61A · Applications · Conclusion
Available
Discussions, homework, and projects
- Discussion 8Algebraic data typesAlgebraic data types and pattern matchingAvailable
- Homework 8Pattern matchingAlgebraic data types and pattern matchingAvailable
- Discussion 9InterpretersWriting an interpreterAvailable
- Homework 9Interpreters and errorsWriting an interpreter · Error handlingAvailable
- Project 4SchemeEnvironments and closures · Linked lists and trees · Algebraic data types and pattern matching · Writing an interpreter · Error handlingAvailable
- Discussion 10ConcurrencyConcurrency with async and awaitAvailable
- Discussion 11TestingTestingAvailable
- Homework 10Concurrency and testingConcurrency with async and await · TestingAvailable
Unit 4
Building data structures
References and memory, linked lists and resizing arrays built from scratch, inheritance and interfaces, iteration and equality, and SwiftUI for drawing. CS61B’s first five weeks.
- 25References, identity, and memory
When two names refer to one thing, who owns it?CS61B · Intro to Java · Defining and Using Classes · Lists, Arrays, Maps, References
Available - 26Drawing with SwiftUI
How does a program draw a world that keeps changing?CS61B · For Project 0: Particle Simulator
Available - 27Testing data structures
How do you test code that holds a million things?CS61B · Testing · Packages
Available - 28IntLists and SLLists
Why hide a list’s nodes from the people who use it?CS61B · Recursion, IntLists · SLLists, Nested Classes, Sentinel Nodes
Available - 29Doubly linked lists and deques
How do you walk a list backward without a cycle of ownership?CS61B · DLLists
Available - 30Arrays from scratch
How can adding to an array be fast on average?CS61B · Basic ALists · Resizing and Circular Arrays
Available - 31Interface and implementation inheritance
Which method runs when two types both define it?CS61B · Interface and Implementation Inheritance · Subtype Polymorphism
Available - 32Iteration, equality, and ordering
What does your type need to work with for-in, ==, and sorted()?CS61B · Iterators, Iterables, and Equals · Comparables and Comparators
Available - 33Copy-on-write collections
How can a copy be free until someone changes it?CS61B · Swift addition: value semantics for collections
Available
Discussions, homework, and projects
- Discussion 12Swift reviewReferences, identity, and memoryAvailable
- Discussion 13References, classes, and arraysReferences, identity, and memoryAvailable
- Homework 11Swift warm-upReferences, identity, and memoryAvailable
- Project 5Particle SimulatorReferences, identity, and memory · Drawing with SwiftUIAvailable
- Discussion 14IntLists and SLListsIntLists and SLListsAvailable
- Homework 12IntListsTesting data structures · IntLists and SLListsAvailable
- Project 6LinkedListDequeTesting data structures · IntLists and SLLists · Doubly linked lists and dequesAvailable
- Discussion 15DLLists, default implementations, and array listsDoubly linked lists and deques · Arrays from scratch · Interface and implementation inheritanceAvailable
- Project 7ArrayDequeArrays from scratch · Interface and implementation inheritance · Iteration, equality, and ordering · Copy-on-write collectionsAvailable
- Discussion 16Comparables and iteratorsIteration, equality, and orderingAvailable
- Homework 13Review IReferences, identity, and memory · IntLists and SLLists · Doubly linked lists and deques · Arrays from scratch · Interface and implementation inheritance · Iteration, equality, and orderingAvailable
Unit 5
Analysis and search trees
Measuring algorithms with asymptotic analysis, disjoint sets, and the trees behind sets and maps: binary search trees, B-trees, red-black trees, and heaps. CS61B’s weeks 5 to 8.
- 34Asymptotic analysis
How do you compare algorithms without a stopwatch?CS61B · Asymptotics I
Available - 35Disjoint sets
Are these two things connected?CS61B · Disjoint Sets
Available - 36Analyzing recursion
How much work does a function that calls itself do?CS61B · Asymptotics II
Available - 37Amortized analysis and the limits of big O
When is an occasional slow step fine?CS61B · Asymptotics III
Available - 38Sets, maps, and binary search trees
How do you find a key without looking at every one?CS61B · Sets, Extends, and BSTs
Available - 39B-trees
How can a tree stay balanced whatever order things arrive in?CS61B · B-Trees
Available - 40Left-leaning red-black trees
Can a binary tree pretend to be a B-tree?CS61B · Red-Black Trees
Available - 41Heaps and priority queues
What is the fastest way to always know the smallest item?CS61B · Heaps, Priority Queues, and Tree Representations
Available
Discussions, homework, and projects
- Discussion 17Asymptotics and disjoint setsAsymptotic analysis · Disjoint setsAvailable
- Project 8PercolationTesting data structures · Drawing with SwiftUI · Disjoint setsAvailable
- Discussion 18Asymptotics IIAnalyzing recursion · Amortized analysis and the limits of big OAvailable
- Homework 14Asymptotic analysisAsymptotic analysis · Analyzing recursion · Amortized analysis and the limits of big OAvailable
- Discussion 19BSTs, B-trees, and LLRBsSets, maps, and binary search trees · B-trees · Left-leaning red-black treesAvailable
- Homework 15BSTMapIteration, equality, and ordering · Sets, maps, and binary search treesAvailable
Unit 6
Graphs
SwiftUI for data-driven apps, tree and graph traversals, shortest paths, minimum spanning trees, and reductions, with a project that charts the history of words and explores WordNet. CS61B’s weeks 8 to 10.
- 42Data-driven apps with SwiftUI
How does a view keep up with data that changes?CS61B · For Project 4: NGordNet
Available - 43Tree and graph traversals
In what order should you visit everything?CS61B · Tree and Graph Traversals
Available - 44Graph implementations
How should a program store a web of connections?CS61B · Graph Traversals and Implementations
Available - 45Shortest paths: Dijkstra and A*
What is the cheapest way from here to there?CS61B · Shortest Paths
Available - 46Minimum spanning trees
How do you connect everything as cheaply as possible?CS61B · Minimum Spanning Trees
Available - 47DAGs, topological sort, and reductions
How can one problem be solved by turning it into another?CS61B · Directed Acyclic Graphs
Available
Discussions, homework, and projects
- Discussion 20Tree traversals and graphsTree and graph traversals · Graph implementationsAvailable
- Project 9NGordNetSets, maps, and binary search trees · Data-driven apps with SwiftUI · Tree and graph traversals · Graph implementationsAvailable
- Discussion 21Shortest paths and MSTsShortest paths: Dijkstra and A* · Minimum spanning trees · DAGs, topological sort, and reductionsAvailable
Unit 7
Hashing, sorting, and software engineering
Hash tables and tries, designing large programs, the major sorting algorithms and the limits of sorting, compression, and the responsibilities that come with computing, finishing with a game in SwiftUI. CS61B’s last five weeks.
- 48Hash tables
How can a lookup take the same time for ten items or ten million?CS61B · Hashing I
Available - 49Hash functions
What makes a hash function good?CS61B · Hashing II
Available - 50Tries and prefix operations
How do you find every word that starts with “ca”?CS61B · Tries
Available - 51Software engineering: managing complexity
Why do large programs become hard to change?CS61B · Software Engineering I
Available - 52Games with SwiftUI
How does a game listen, update, and remember?CS61B · For Project 5: Build Your Own World
Available - 53Designing a world
How do you plan a program too big to hold in your head?CS61B · Software Engineering II · BYOW Warmup
Available - 54Basic sorts
How many ways are there to put things in order?CS61B · Basic Sorts · Insertion Sort
Available - 55Quicksort and selection
Why is the sort with the worst worst case so often the fastest?CS61B · Quicksort
Available - 56The limits of sorting
Can any comparison sort beat n log n?CS61B · Sorting and Algorithmic Bounds
Available - 57Radix sorts
How can you sort without comparing?CS61B · Radix Sorts
Available - 58Compression and complexity
How small can a file get?CS61B · Compression
Available - 59Computing, society, and what comes next
What do we owe the people who use our software?CS61B · Social Implications of Computing · AI in Software Engineering · Summary
Available
Discussions, homework, and projects
- Discussion 22Hashing and triesHash tables · Hash functions · Tries and prefix operationsAvailable
- Homework 16Review IISets, maps, and binary search trees · Heaps and priority queues · Tree and graph traversals · Shortest paths: Dijkstra and A* · Hash tables · Tries and prefix operationsAvailable
- Discussion 23Hashing and tries, revisitedHash tables · Hash functions · Tries and prefix operationsAvailable
- Project 10Build Your Own WorldDisjoint sets · Tree and graph traversals · Software engineering: managing complexity · Games with SwiftUI · Designing a worldAvailable
- Discussion 24SortingBasic sorts · Quicksort and selectionAvailable
- Homework 17HashMapHash tables · Hash functionsAvailable
- Discussion 25Sorting IIThe limits of sorting · Radix sortsAvailable
- Homework 18LLRB setLeft-leaning red-black treesAvailable
- Homework 19Final reviewHeaps and priority queues · Shortest paths: Dijkstra and A* · Minimum spanning trees · Hash tables · Quicksort and selection · The limits of sorting · Radix sorts · Compression and complexityAvailable