Implemented the Dependency property wrapper.

This commit is contained in:
Javier Cicchelli 2022-12-05 22:51:56 +01:00
parent 7849945ebf
commit a9c81f44fa

View File

@ -0,0 +1,29 @@
//
// Dependency.swift
// DependencyService
//
// Created by Javier Cicchelli on 05/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
@propertyWrapper
public struct Dependency<D> {
// MARK: Properties
private let keyPath: WritableKeyPath<DependencyStore, D>
// MARK: Computed
public var wrappedValue: D {
get { DependencyStore[keyPath] }
set { DependencyStore[keyPath] = newValue }
}
// MARK: Initialisers
public init(_ keyPath: WritableKeyPath<DependencyStore, D>) {
self.keyPath = keyPath
}
}