<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Scene/environment(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5ScenePAAE11environmentyQrqd__SgRld__C11Observation10ObservableRd__lF"
  },
  "title" : "environment(_:)"
}
-->

# environment(_:)

Places an observable object in the scene’s environment.

```
nonisolated func environment<T>(_ object: T?) -> some Scene where T : AnyObject, T : Observable
```

## Parameters

`object`

The object to set for this object’s type in the
environment, or `nil` to clear an object of this type from the
environment.

## Return Value

A scene that has the specified object in its environment.

## Discussion

Use this modifier to place an object that you declare with the
<doc://com.apple.documentation/documentation/Observation/Observable()>
macro into a scene’s environment. For example, you can add an instance
of a custom observable `Profile` class to the environment of a
[`WindowGroup`](/documentation/SwiftUI/WindowGroup) scene:

```
@Observable class Profile { ... }

@main
struct MyApp: App {
    var body: some View {
        WindowGroup {
            ContentView()
        }
        .environment(Profile.currentProfile)
    }
}
```

You then read the object inside `ContentView` or one of its descendants
using the [`Environment`](/documentation/SwiftUI/Environment) property wrapper:

```
struct ContentView: View {
    @Environment(Profile.self) private var currentProfile: Profile

    var body: some View { ... }
}
```

This modifier affects the given scene, as well as the scene’s descendant
views. It has no effect outside the view hierarchy on which you call it.
The environment of a given view hierarchy holds only one observable
object of a given type.

> Note: This modifier takes an object that conforms to the
> <doc://com.apple.documentation/documentation/Observation/Observable>
> protocol. To add environment objects that conform to the
> <doc://com.apple.documentation/documentation/Combine/ObservableObject>
> protocol, use ``doc://com.apple.SwiftUI/documentation/SwiftUI/Scene/environmentObject(_:)`` instead.

---

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)