---
title: "environmentObject(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/environmentobject(_:)"
---

# environmentObject(_:)

Supplies an observable object to a view’s hierarchy.

## Declaration

```swift
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

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. note: If the observable object conforms to the Observable protocol, use either environment(_:) or the environment(_:_:) modifier to add the object to the view’s environment.

## See Also

### Distributing model data throughout your app

- [environmentObject(_:)](swiftui/scene/environmentobject(_:).md)
- [EnvironmentObject](swiftui/environmentobject.md)
