30 lines
604 B
Swift
30 lines
604 B
Swift
|
//
|
||
|
// 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
|
||
|
}
|
||
|
|
||
|
}
|