Skip to content

ComposableDependencies

tgrapperon edited this page Aug 31, 2021 · 4 revisions

ComposableDependencies

This type acts as a namespace to reference your dependencies.

public struct ComposableDependencies 

To declare a dependency, create a DependencyKey, and declare a computed property in this type like you would declare a custom EnvironmentValue in SwiftUI. For example, if UUIDGeneratorKey is a DependencyKey with DependencyKey/Value == () -> UUID:

extension ComposableDependencies {
  var uuidGenerator: () -> UUID {
    get { self[UUIDGeneratorKey.self] }
    set { self[UUIDGeneratorKey.self] = newValue }
  }
}

This dependency can then be referenced by its keypath \.uuidGenerator when invoking the Dependency property wrapper in some ComposableEnvironment subclass.

Clone this wiki locally