<!--
{
  "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/Environment/init(_:)-8slkf",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI11EnvironmentVyACyqd__SgGqd__mcADRszRld__C11Observation10ObservableRd__lufc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates an environment property to read an observable object from the
environment, returning `nil` if no corresponding object has been set in
the current view’s environment.

```
init<T>(_ objectType: T.Type) where Value == T?, T : AnyObject, T : Observable
```

## Parameters

`objectType`

The type of the `Observable` object to read
from the environment.

## Discussion> Important: This initializer only accepts objects conforming to the
> `Observable` protocol. For reading environment objects that conform to
> `ObservableObject`, use ``EnvironmentObject`` instead.

Don’t call this initializer directly. Instead, declare an optional
property with the `Environment` property wrapper, passing the object’s
type to the wrapper:

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

struct MyView: View {
    @Environment(Profile.self) private var currentProfile: Profile?

    // ...
}
```

If no object has been set in the view’s environment, this property will
return `nil` as its wrapped value.

SwiftUI automatically updates any parts of `MyView` that depend on the
property when the associated environment object changes.

You can’t modify the environment object using a property like this.
Instead, use the `View/environment(_:)` view modifier on a view
to set an object for a view hierarchy.

---

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)