@EnvironmentObject for Shared State
Injecting shared models into deep view hierarchies without prop-drilling.
Welcome
`@EnvironmentObject` injects a shared model into any view in the hierarchy without explicit passing — ideal for app-wide state like user authentication or theme settings.
Injecting into the Hierarchy
```swift
struct App: App {
@StateObject var authModel = AuthModel()
var body: some Scene {
WindowGroup {
RootView().environmentObject(authModel)
}
}
}
```
All lessons in this course
- @Binding: Two-Way Data Flow
- @ObservableObject and @StateObject
- @EnvironmentObject for Shared State
- Single Source of Truth and Unidirectional Flow