- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10
Dependency
        tgrapperon edited this page Aug 22, 2022 
        ·
        7 revisions
      
    Use this property wrapper to declare depencies in a ComposableEnvironment subclass.
@propertyWrapper
public struct Dependency<Value> You reference the dependency by its KeyPath originating from  Dependencies, and
you declare its name in the local environment. The dependency should not be instantiated, as it
is either inherited from a ComposableEnvironment parent, or installed with
ComposableEnvironment/with(_:_:).
For example, if the dependency is declared as:
extension Dependencies {
  var uuidGenerator: () -> UUID {
    get { self[UUIDGeneratorKey.self] }
    set { self[UUIDGeneratorKey.self] = newValue }
  }
},you can install it in LocalEnvironment like:
class LocalEnvironment: ComposableEnvironment {
  @Dependency(\.uuidGenerator) var uuid
}This exposes a var uuid: () -> UUID read-only property in the LocalEnvironment. This
property can then be used as any vanilla dependency.
See Dependency discussion
public init(_ keyPath: WritableKeyPath<Dependencies, Value>) @available(
    *, unavailable,
    message:
      """
  @Dependency should be used in conjunction with a `WritableKeyPath`. Please implement a setter
  part in the `Dependencies`'s computed property for this dependency.
  """
  )
  public init(_ keyPath: KeyPath<Dependencies, Value>) See Dependency discussion
public init(_ keyPath: KeyPath<Dependencies, Value>) @available(
    *, unavailable, message: "@Dependency should be used in a ComposableEnvironment class."
  )
  public var wrappedValue: Value public var wrappedValue: Value Generated at 2022-08-22T21:22:01+0000 using swift-doc 1.0.0-rc.1.