init()
Creates an environment values instance.
環境値インスタンスを作成します。
var description: String
A string that represents the contents of the environment values instance.
ある文字列、それは環境値インスタンスの内容を表します。
Availability 有効性
Technology
subscript<K>(key: K.Type) -> K.Value where K : EnvironmentKey
{ get set }
Create custom environment values by defining a key that conforms to the Environment
protocol, and then using that key with the subscript operator of the Environment
structure to get and set a value for that key:
private struct MyEnvironmentKey: EnvironmentKey {
static let defaultValue: String = "Default value"
}
extension EnvironmentValues {
var myCustomValue: String {
get { self[MyEnvironmentKey.self] }
set { self[MyEnvironmentKey.self] = newValue }
}
}
You use custom environment values the same way you use system-provided values, setting a value with the environment(_:
view modifier, and reading values with the Environment
property wrapper. You can also provide a dedicated view modifier as a convenience for setting the value:
extension View {
func myCustomValue(_ myCustomValue: String) -> some View {
environment(\.myCustomValue, myCustomValue)
}
}
init()
var description: String