Skip to main content Skip to secondary navigation
Main content start

The lectures for the Spring 2021 version of Stanford University's course CS193p (Developing Applications for iOS using SwiftUI) were once again delivered to our students in an on-line fashion due to the novel coronavirus outbreak.   You can watch them all on Stanford's YouTube channel (links below).  This website was set up to give everyone access to the supporting material that was distributed to students during the quarter (homework, demo code, etc.).

The curriculum is substantially similar to the Spring 2020 version, so if you have already watched that version, scrubbing through the 2021 videos might be of some value since there were quite a lot of enhancements made to SwiftUI since 2020.

For more, check out the About page.

Memorize Game
Lecture 1

Getting Started with SwiftUI

The first lecture jumps right into building the first application of the quarter: a card-matching game called Memorize.  It will be the foundation for the first few weeks of course material.

Watch Video

MVVM Flowchart
Lecture 3


Conceptual overview of the architectural paradigm underlying the development of applications for iOS using SwiftUI (known as MVVM) and an explanation of a fundamental component of understanding the Swift programming language: its type system.  Then both of these are applied to the Memorize application started in the first two lectures.

Watch Video

Description of Optionals
Lecture 4

More MVVM enum Optionals

The MVVM architecture is fully applied to Memorize.  The important Swift concepts of enums and Optionals are covered and used to finish off the game logic of the Memorize game.

Watch Video

Reading Assignment 2

Programming Assignment 2

Fit to Geometry
Lecture 5

Properties Layout @ViewBuilder

Explore property observers, computed properties, @State and @ViewBuilder.  The mechanisms behind how Views are layed out on screen are examined followed by a demo which chooses a better font for each card in Memorize depending on the space available.  Along the way, apply better access control to Memorize's internal API.

Watch Video

Pie Shape
Lecture 6

Protocols Shapes

Discussion of what is perhaps the most important type in Swift: a protocol.  The demo combines the concepts of generics and protocols to make the cards better use the space available on screen.  Finally the Shape protocol is explained and the pie-shaped countdown timer is added to Memorize (but not yet animated).

Watch Video

Reading Assignment 3

Programming Assignment 3

Lecture 7

ViewModifier Animation

The ViewModifier protocol is explained and then used to make it possible to turn any View into a Memorize card by "cardify-ing" it.  The lecture then moves on to an in-depth look at animation and starts a comprehensive multi-lecture demonstration of animation by using implicit animations to make the emoji on a Memorize card spin around when it is matched.

Watch Video

Card Animation
Lecture 8

Animation Demo

The demonstration of animation continues by showing how to animate the shuffling, dealing and flipping of cards along with the cards' appearance and disappearance.  The pie-shaped countdown timer added in a previous lecture is also animated.

Watch Video

Programming Assignment 4

L7+L8 Demo Code

Lecture 9

EmojiArt Drag/Drop

New demo application: EmojiArt. Lots covered here, including enum, extensions, tuples, Drag and Drop, colors and images, and more.  The Grand Central Dispatch (GCD) API is explained in preparation for a demo of multithreading in the next lecture.

Note: GCD has been mostly replaced by Swift's new built-in async API as of WWDC 2021.

Watch Video

Resizing Image
Lecture 10


After demonstrating how to use GCD to keep the downloading of the background image from the internet from blocking the responsiveness of the UI, multitouch gestures are added to zoom in on and pan around in our EmojiArt document.

Note: GCD has been mostly replaced by Swift's new built-in async API as of WWDC 2021.

Watch Video

Programming Assignment 5

L9+L10 Demo Code

Saving Code
Lecture 11

Persistence Error Handling

A number of persistence topics (UserDefaults, the file system, Codable archiving, JSON) as well as how errors are handled in Swift.  Make changes to an EmojiArt document persist and introduce a new ViewModel to EmojiArt called PaletteStore.

Watch Video

Palette Manager
Lecture 12

Binding Sheet Navigation EditMode

The details about numerous property wrappers, including @State, @ObservedObject, @Binding, @Environment, @EnvironmentObject and @StateObject.  Demo of many new SwiftUI elements, including TextField, Form, NavigationView, List, sheet, popover, Alert, EditMode and more.  Enhance EmojiArt's palettes of emoji.

Watch Video

Programming Assignment 6

L11+L12 Demo Code

Publisher Code
Lecture 13

Publisher More Persistence

The Publisher protocol is used to implement a cleaner version of EmojiArt's background downloading code.  CloudKit and CoreData are briefly explained (but not demoed).  See the bonus lecture from 2020 below (Enroute, part 2) for a demo of CoreData.

Watch Video

Document Editing
Lecture 14

Document Architecture

Demonstration of using SwiftUI's Document Architecture to turn EmojiArt into a multi-document application.  Includes discussion of the App and Scene protocols, WindowGroup, DocumentGroup, @SceneStorage, @ScaledMetric, and more.  Along the way, we add Undo/Redo to EmojiArt.

Watch Video

Photo Chooser
Lecture 15

UIKit Integration

Get EmojiArt working on iPhone.  Includes some more toolbar work as well as understanding how to integrate UIKit functionality into a SwiftUI application.

Watch Video

Mac UI
Lecture 16

Multiplatform (macOS)

Turn EmojiArt into a multi-platform application (i.e. both iOS and macOS).  Demonstrates a variety of ways to share code across platforms.

Watch Video

L15+L16 Demo Code


The following two lectures (Enroute) were given in Spring 2020, but not in Spring 2021.  The material covered (Picker, using Codable to pull data from a REST API, and CoreData) is still relevant (as of Spring 2021 anyway), so those lectures are included here as well.  Updated demo code (to Xcode 12) is also included (the only significant change is to use the new SwiftUI application architecture, i.e. EnrouteApp.swift instead of SceneDelegate.swift, et. al.).

Picker Demo
2020 Enroute Part 1

Enroute Picker Codable REST API

The first of two bonus lectures from 2020 covers Picker and creates a new demonstration application (Enroute) which pulls data from a REST API on the internet using the Codable mechanism shown earlier in the course.

Watch Video

Demo (as shown in lecture)

Demo (updated for Xcode 12)

Sunset view from Stanford Campus