PROTOCOL
ViewEnvironmentKey
¶
public protocol ViewEnvironmentKey
A key into the ViewEnvironment.
Environment keys are associated with a specific type of value (Value
) and
must declare a default value.
Typically the key conforming to ViewEnvironmentKey
will be private, and
you are encouraged to provide a convenience accessor on ViewEnvironment
as in the following example:
private enum ThemeKey: ViewEnvironmentKey {
typealias Value = Theme
var defaultValue: Theme
}
extension ViewEnvironment {
public var theme: Theme {
get { self[ThemeKey.self] }
set { self[ThemeKey.self] = newValue }
}
}
Properties¶
defaultValue
¶
static var defaultValue: Value