Skip to main content Skip to secondary navigation

2021

Main content start

The lectures for the Spring 2021 version of Stanford University's course CS193p (Developing Applications for iOS using SwiftUI) are archived here. They are are all now out of date and you'll want to go to the Spring 2023 version instead.

For more, check out the About page.

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

 
Lecture 3

MVVM

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

 
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

 
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

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

Lecture 10

Gestures

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

 
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

 
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

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

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

 
 
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

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 (nor in Spring 2023).  Some of the material covered (e.g. Picker and using Codable to pull data from a REST API) is still somewhat relevant (as of Spring 2021 anyway, though less-so in Spring 2023) but CoreData is being replaced with SwiftData and so the second of these two lectures is now out of date.

 
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)

 
2020 Enroute Part 2

Core Data

The second of two lectures from 2020 which use the Enroute demonstration application.  Adds a CoreData database to Enroute to store historical flight data.  CoreData is being replaced/upgraded to the SwiftData framework starting mid-2023 (after CS193p was given in 2023 unfortunately), so this lecture's content has gotten quite stale.

Watch Video

Demo Code (as shown in lecture)

Demo Code (updated for Xcode 12)

 
Sunset view from Stanford Campus