# environment value

[SwiftUI](../..) ⟩ [view](..) ⟩ [environment]() ⟩ 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](../state). 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](../../../swift/type/ext) 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](value/dismiss "mention")：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 %}
