@Environment & Presenting Screens

One object, needed everywhere

PawWalk has one object that nearly every screen cares about: AuthSession, the view model that knows who is signed in. The root view needs it to decide login-vs-home; the login screen calls its logIn; the profile screen shows its currentUser; the home screen greets them by name.

You could pass it as an init parameter into every view, through every view in between β€” even views that don't use it. That's called prop drilling, and it turns every new screen into plumbing work.

SwiftUI's fix is the environment: a bag of shared values that flows down the view tree. Inject an object once at the root with .environment(object), and any descendant β€” child, grandchild, a sheet presented five levels deep β€” can ask for it by type. No plumbing in between.