Skip to content

DerivedEnvironment

tgrapperon edited this page Aug 31, 2021 · 8 revisions

DerivedEnvironment

Use this property wrapper to declare child ComposableEnvironment in a ComposableEnvironment subclass.

@propertyWrapper
public final class DerivedEnvironment<Value> where Value: ComposableEnvironment 

You only need to specify the subclass used and its name. You don't need to instantiate the subclass. For example, if ChildEnvironment is a ComposableEnvironment subclass, you can install a representant in ParentEnvironment as:

class ParentEnvironment: ComposableEnvironment {
  @DerivedEnvironment<ChildEnvironment> var child
}.

This exposes a var child: ChildEnvironment read-only property in the ParentEnvironment. This child environment inherits the current dependencies of all its ancestor. They can be exposed using the Dependency property wrapper.

Initializers

init(wrappedValue:)

See DerivedEnvironment discussion

public init(wrappedValue: Value) 

init()

See DerivedEnvironment discussion

public init() 

Properties

wrappedValue

@available(*, unavailable, message: "@DerivedEnvironment should be used in a ComposableEnvironment class.")
  public var wrappedValue: Value 

Clone this wiki locally