Contents

environmentObject(_:)

Supplies an observable object to a view’s hierarchy.

Declaration

nonisolated func environmentObject<T>(_ object: T) -> some View where T : ObservableObject

Parameters

  • object:

    The object to store and make available to the view’s hierarchy.

Discussion

Use this modifier to add an observable object to a view’s environment. The object must conform to the ObservableObject protocol.

Adding an object to a view’s environment makes the object available to subviews in the view’s hierarchy. To retrieve the object in a subview, use the EnvironmentObject property wrapper.

See Also

Distributing model data throughout your app