From 51577d96c18d1ce0c74030d2f69e010357bd6934 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sun, 3 Nov 2024 15:17:12 +0100 Subject: [PATCH] Resolver fixed --- Calcium/CalciumApp.swift | 6 +++--- Calcium/CalculatorClient.swift | 23 +++++++++++++---------- Calcium/MainReducer.swift | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Calcium/CalciumApp.swift b/Calcium/CalciumApp.swift index 1ef02ec..77bac6f 100644 --- a/Calcium/CalciumApp.swift +++ b/Calcium/CalciumApp.swift @@ -8,15 +8,15 @@ import CalciumCommon import ComposableArchitecture - import Resolver import SwiftUI @main struct CalciumApp: App { init() { - // Resolver.register { NativeCalculator() } - // .implements(Calculator.self) + Resolver.register(Calculator.self, name: .name(fromString: "calculator")) { + NativeCalculator() + } } var body: some Scene { diff --git a/Calcium/CalculatorClient.swift b/Calcium/CalculatorClient.swift index 4ace18e..96cbaa1 100644 --- a/Calcium/CalculatorClient.swift +++ b/Calcium/CalculatorClient.swift @@ -8,24 +8,27 @@ import CalciumCommon import ComposableArchitecture - -import Resolver +@preconcurrency import Resolver @DependencyClient struct CalculatorClient: Sendable, DependencyKey, TestDependencyKey { var calculateValue: @Sendable (String, String, CalciumCommon.Operation) -> String = { _, _, _ in "" } - static let previewValue = // @Injected var calculator: Calculator - - Self(calculateValue: { - NativeCalculator().calculateValue(lhs: $0, rhs: $1, operation: $2) - }) + static let previewValue = CalculatorClient( + calculateValue: { + Resolver.resolve( + Calculator.self, + name: .name(fromString: "calculator") + ).calculateValue(lhs: $0, rhs: $1, operation: $2) + } + ) static let liveValue = CalculatorClient( calculateValue: { - // @Injected var calculator: Calculator - - NativeCalculator().calculateValue(lhs: $0, rhs: $1, operation: $2) + Resolver.resolve( + Calculator.self, + name: .name(fromString: "calculator") + ).calculateValue(lhs: $0, rhs: $1, operation: $2) } ) diff --git a/Calcium/MainReducer.swift b/Calcium/MainReducer.swift index 2a3f4a3..654935d 100644 --- a/Calcium/MainReducer.swift +++ b/Calcium/MainReducer.swift @@ -140,7 +140,7 @@ struct MainReducer { guard let lhs, let rhs else { throw MainReducerError.invalidValues } - let value = await Task { + let value = await Task { @MainActor in let result = calculator.calculateValue( lhs.asString(radix: 10), rhs.asString(radix: 10),