> 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/value.md).

# environment value

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

{% hint style="success" %}
A <mark style="color:yellow;">defined collection of values</mark> related to a view.

* Some of these automatically reflect <mark style="color:orange;">system state</mark>, <mark style="color:orange;">user settings</mark>, or [view state](/ios/swiftui/view/state.md). Examples include the color scheme, text style, or focus state of the view.&#x20;
* Others provide useful <mark style="color:yellow;">default values</mark>, such as a line limit for text fields.
  {% endhint %}

```swift
// read the color scheme (an environment value) of the current view
@Environment(\.colorScheme) var colorScheme: ColorScheme
```

* Find many <mark style="color:yellow;">built-in</mark> <mark style="color:purple;">environment values</mark> in [`EnvironmentValues`](https://developer.apple.com/documentation/swiftui/environmentvalues).&#x20;
* Create a <mark style="color:yellow;">custom</mark> [`EnvironmentValues`](https://developer.apple.com/documentation/swiftui/environmentvalues) <mark style="color:yellow;">property</mark> by:&#x20;
  * defining a new property in an [extension](/ios/swift/type/ext.md) to the <mark style="color:orange;">`EnvironmentValues`</mark> structure and&#x20;
  * applying the [`Entry()`](https://developer.apple.com/documentation/swiftui/entry\(\)) <mark style="color:orange;">macro</mark> to the variable declaration.

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

* [dismiss](/ios/swiftui/view/environment/value/dismiss.md)：An action that dismisses the current presentation.
  {% endtab %}

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

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