STRUCT
ViewEnvironment
¶
public struct ViewEnvironment
ViewEnvironment acts as a container for values to flow down the view-side of a rendering tree (as opposed to being passed down through Workflows).
This will often be used by containers to let their children know in what context theyโre appearing (for example, a split screen container may set the environment of its two children according to which position theyโre appearing in).
Properties¶
empty
¶
public static let empty: ViewEnvironment = ViewEnvironment()
An empty view environment. This should only be used when setting up a root workflow into a root ContainerViewController or when writing tests. In other scenarios, containers should pass down the ViewEnvironment value they get from above.
Methods¶
setting(key:to:)
¶
public func setting<Key>(key: Key.Type, to value: Key.Value) -> ViewEnvironment where Key: ViewEnvironmentKey
Returns a new ViewEnvironment with the given value set for the given environment key.
This is provided as a convenience for modifying the environment while passing it down to children screens without the need for an intermediate mutable value. It is functionally equivalent to the subscript setter.
setting(keyPath:to:)
¶
public func setting<Value>(keyPath: WritableKeyPath<ViewEnvironment, Value>, to value: Value) -> ViewEnvironment
Returns a new ViewEnvironment with the given value set for the given key path.
This is provided as a convenience for modifying the environment while passing it down to children screens.
The following are functionally equivalent:
var newEnvironment = environment
newEnvironment.someProperty = 42
let newEnvironment = environment.setting(\.someProperty, to: 42)