Episode #440

SwiftUI Environment

9 minutes
Published on May 18, 2020

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

It can be cumbersome to pass values from parent to child view to configure something. For instance, setting a font for many Text views inside of a VStack. Luckily there is a .font() modifier that can do this for you. How does it work? It sets a value in the Environment using an EnvironmentKey. In this episode we will learn how to leverage the SwiftUI environment to pass values to descendent views, regardless of their depth from where it is set.

This episode uses Xcode 11.4, Swift 5.2.