
Stanford CS193p: iOS Development with SwiftUI | 2025 | L6: Demonstrating Data Flow
All course materials are available at https://cs193p.stanford.edu.
The 6th lecture of the 2025 version of Stanford's CS193p course (developing applications for iOS using SwiftUI). This lecture is entirely demo-focused, covering advanced data flow patterns in SwiftUI. Implements a peg chooser keyboard interface to improve user input beyond the tap-to-cycle method. Key topics include: file organization with extract-to-file refactoring, creating PegView as a reusable component, using // MARK comments for code organization, implementing @State for selection tracking, and creating Buttons with custom Views as labels. Demonstrates data flow from user input through View interactions to Model updates, showing how Views become visual manifestations of Model state. Introduces ForEach without indices when data is unique, an extension to add custom Color.gray() function with brightness parameters, and the difference between CGFloat (for drawing) and Double (for general math). The implementation shows practical SwiftUI patterns like trailing closure syntax with multiple closures, guard statements for defensive programming, and proper @State management for UI state that doesn't belong in the Model.
Paul Hegarty is a Lecturer who has been teaching CS193p at Stanford since 2010.
The 6th lecture of the 2025 version of Stanford's CS193p course (developing applications for iOS using SwiftUI). This lecture is entirely demo-focused, covering advanced data flow patterns in SwiftUI. Implements a peg chooser keyboard interface to improve user input beyond the tap-to-cycle method. Key topics include: file organization with extract-to-file refactoring, creating PegView as a reusable component, using // MARK comments for code organization, implementing @State for selection tracking, and creating Buttons with custom Views as labels. Demonstrates data flow from user input through View interactions to Model updates, showing how Views become visual manifestations of Model state. Introduces ForEach without indices when data is unique, an extension to add custom Color.gray() function with brightness parameters, and the difference between CGFloat (for drawing) and Double (for general math). The implementation shows practical SwiftUI patterns like trailing closure syntax with multiple closures, guard statements for defensive programming, and proper @State management for UI state that doesn't belong in the Model.
Paul Hegarty is a Lecturer who has been teaching CS193p at Stanford since 2010.
Stanford Online
You can gain access to a world of education through Stanford Online, the Stanford School of Engineering’s portal for academic and professional education offered by schools and units throughout Stanford University. https://online.stanford.edu/
Our robust ...