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

# init(_:)

Creates an environment property to read the specified key path.

```
init(_ keyPath: KeyPath<EnvironmentValues, Value>)
```

## Parameters

`keyPath`

A key path to a specific resulting value.

## Discussion

Don’t call this initializer directly. Instead, declare a property
with the [`Environment`](/documentation/SwiftUI/Environment) property wrapper, and provide the key path of
the environment value that the property should reflect:

```
struct MyView: View {
    @Environment(\.colorScheme) var colorScheme: ColorScheme

    // ...
}
```

SwiftUI automatically updates any parts of `MyView` that depend on
the property when the associated environment value changes.
You can’t modify the environment value using a property like this.
Instead, use the [`environment(_:_:)`](/documentation/SwiftUI/View/environment(_:_:)) view modifier on a view to
set a value 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)