Implemented the Dependency property wrapper.
This commit is contained in:
parent
7849945ebf
commit
a9c81f44fa
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user