> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/view/environment.md).

# view environment

[SwiftUI](/ios/swiftui.md) ⟩ [view](/ios/swiftui/view.md) ⟩ environment

{% hint style="success" %}
A <mark style="color:purple;">view's environment</mark> provides access to the view's [environment values](https://developer.apple.com/documentation/swiftui/environmentvalues).&#x20;
{% endhint %}

A view <mark style="color:yellow;">inherits</mark> its <mark style="color:purple;">environment</mark> from its [container view](/ios/swiftui/view/hierarchy/container.md)：&#x20;

* subject to <mark style="color:yellow;">explicit changes</mark> from an [`environment(_:_:)`](https://developer.apple.com/documentation/swiftui/view/environment\(_:_:\)) view modifier,&#x20;
* or by <mark style="color:red;">implicit changes</mark> from one of the many [modifiers](/ios/swiftui/view/modifier.md) that operate on [environment values](/ios/swiftui/view/environment/value.md).&#x20;

As a result, you can <mark style="color:yellow;">configure a entire hierarchy of views</mark> by <mark style="color:yellow;">modifying</mark> the <mark style="color:purple;">environment</mark> of the group’s [container](/ios/swiftui/view/hierarchy/container.md).

```swift
// read values from environment
@Environment(\.colorScheme) var colorScheme: ColorScheme
```

{% tabs %}
{% tab title="🔴 主題" %}

* [@StateObject](/ios/swiftui/view/state/object/stateobject.md)：declare & init a [state object](/ios/swiftui/view/state/object.md)
* [@Environment](/ios/swiftui/view/environment/environment.md)：read an [environment value](/ios/swiftui/view/environment/value.md)&#x20;
* view[.environmentObject(\_:)](https://developer.apple.com/documentation/swiftui/scene/environmentobject\(_:\))：put an [environment object](/ios/swiftui/view/environment/object.md)&#x20;
* [@EnvironmentObject](/ios/swiftui/view/environment/environmentobject.md)：read an [environment object](/ios/swiftui/view/environment/object.md)&#x20;
  {% endtab %}

{% tab title="📘 手冊" %}

* [SwiftUI](https://developer.apple.com/documentation/swiftui) ⟩ [Environment values](https://developer.apple.com/documentation/swiftui/environment-values)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/view/environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
