A key path to a specific resulting value. 特定の結果値へのキーパス。
Initializer
init(_:)
Creates an environment property to read the specified key path.
環境プロパティを作成してその指定されたキーパスを読み出します。
Availability 有効性
- iOS 13.0+
- iPadOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
Technology
- Swift
UI
Declaration 宣言
init(_ keyPath: KeyPath
<EnvironmentValues
, Value>)
Parameters パラメータ
keyPath
Discussion 議論
Don’t call this initializer directly. Instead, declare a property with the Environment
property wrapper, and provide the key path of the environment value that the property should reflect:
struct MyView: View {
var colorScheme: ColorScheme (\.colorScheme)
// ...
}
SwiftUI automatically updates any parts of My
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(_:
view modifier on a view to set a value for a view hierarchy.