Episode #438

SwiftUI Preferences

14 minutes
Published on May 7, 2020

This video is only available to subscribers. Get access to this video and 576 others.

In SwiftUI we use State to push values from a parent to a child. What if you want to go the other way, passing data about a child up to a parent? To do this we can leverage Preferences. In this episode we will see how to define a custom preference key, how to use an overlay with a GeometryReader to measure the size of a view, and then set a preference with the view's size. Then we'll learn how to respond to preference changes in an ancestor view.

This episode uses Xcode 11.4, Swift 5.2.