<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/environmentObject(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE17environmentObjectyQrqd__7Combine010ObservableE0Rd__lF"
  },
  "title" : "environmentObject(_:)"
}
-->

# environmentObject(_:)

Supplies an observable object to a view’s hierarchy.

```
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
<doc://com.apple.documentation/documentation/Combine/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`](/documentation/SwiftUI/EnvironmentObject) property wrapper.

> Note: If the observable object conforms to the
> <doc://com.apple.documentation/documentation/Observation/Observable>
> protocol, use either ``doc://com.apple.SwiftUI/documentation/SwiftUI/View/environment(_:)`` or the
> ``doc://com.apple.SwiftUI/documentation/SwiftUI/View/environment(_:_:)`` modifier to add the object to the view’s
> environment.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)