From 7849945ebfe03b91fe672e9a47699fbed0ea1b2d Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 5 Dec 2022 22:50:36 +0100 Subject: [PATCH] Implemented the DependencyStore struct. --- .../Structs/DependencyStore.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Libraries/Sources/DependencyService/Structs/DependencyStore.swift diff --git a/Libraries/Sources/DependencyService/Structs/DependencyStore.swift b/Libraries/Sources/DependencyService/Structs/DependencyStore.swift new file mode 100644 index 0000000..88ad1e0 --- /dev/null +++ b/Libraries/Sources/DependencyService/Structs/DependencyStore.swift @@ -0,0 +1,27 @@ +// +// DependencyStore.swift +// DependencyService +// +// Created by Javier Cicchelli on 05/12/2022. +// Copyright © 2022 Röck+Cöde. All rights reserved. +// + +public struct DependencyStore { + + // MARK: Properties + + private static var current = Self() + + // MARK: Functions + + public static subscript(key: K.Type) -> K.Value where K: DependencyKey { + get { key.currentValue } + set { key.currentValue = newValue } + } + + public static subscript(_ keyPath: WritableKeyPath) -> D { + get { current[keyPath: keyPath] } + set { current[keyPath: keyPath] = newValue } + } + +}