diff --git a/{{cookiecutter.app_name}}/Domain/Sources/Domain/Interface/UseCase.swift b/{{cookiecutter.app_name}}/Domain/Sources/Domain/Interface/UseCase.swift
index 6f98f5d..78c9869 100644
--- a/{{cookiecutter.app_name}}/Domain/Sources/Domain/Interface/UseCase.swift
+++ b/{{cookiecutter.app_name}}/Domain/Sources/Domain/Interface/UseCase.swift
@@ -8,9 +8,15 @@
import Foundation
-public protocol UseCase {
+public protocol UseCase {
associatedtype Input
associatedtype Output
- func execute(input: Input) async throws -> Output
+ func callAsFunction(input: Input) async throws -> Output
+}
+
+extension UseCase where Input == Void {
+ public func callAsFunction() async throws -> Output {
+ try await callAsFunction(input: ())
+ }
}
diff --git a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/PrepareCoreDataUseCase.swift b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/PrepareCoreDataUseCase.swift
index 9910880..c0fd941 100644
--- a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/PrepareCoreDataUseCase.swift
+++ b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/PrepareCoreDataUseCase.swift
@@ -8,13 +8,16 @@
import Foundation
-public final class PrepareCoreDataUseCase: UseCase {
+public typealias PrepareCoreDataUseCaseType = UseCase
+
+public class PrepareCoreDataUseCase: UseCase {
var prepare: () async throws -> Void
+
public init(repository: R) {
self.prepare = repository.prepare
}
- public func execute(input: Void) async {
+ public func callAsFunction(input: Void) async {
try? await prepare()
}
}
diff --git a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/ProductUseCase.swift b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/ProductUseCase.swift
index 437c359..2d6beb9 100644
--- a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/ProductUseCase.swift
+++ b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/ProductUseCase.swift
@@ -8,6 +8,8 @@
import Foundation
+public typealias ProductUseCaseType = UseCase
+
public final class ProductUseCase: UseCase {
var getProduct: (_ input: Int) async throws -> Product?
@@ -17,7 +19,7 @@ public final class ProductUseCase: UseCase {
self.getProduct = repository.read(input:)
}
- @Sendable public func execute(input: Int) async throws -> Product? {
+ public func callAsFunction(input: Int) async throws -> Product? {
return try await getProduct(input)
}
}
diff --git a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/SaveProductUseCase.swift b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/SaveProductUseCase.swift
index bdf1b9c..f217a79 100644
--- a/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/SaveProductUseCase.swift
+++ b/{{cookiecutter.app_name}}/Domain/Sources/Domain/UseCases/SaveProductUseCase.swift
@@ -8,6 +8,8 @@
import Foundation
+public typealias SaveProductUseCaseType = UseCase
+
public final class SaveProductUseCase: UseCase {
var saveProduct: (_ input: Product) async throws -> Void
@@ -16,7 +18,7 @@ public final class SaveProductUseCase: UseCase {
self.saveProduct = repository.create(input:)
}
- @Sendable public func execute(input: Product) async throws {
+ public func callAsFunction(input: Product) async throws {
return try await saveProduct(input)
}
}
diff --git a/{{cookiecutter.app_name}}/Features/Sources/App/AppClient.swift b/{{cookiecutter.app_name}}/Features/Sources/App/AppClient.swift
index aa2a84c..0b2b8d3 100644
--- a/{{cookiecutter.app_name}}/Features/Sources/App/AppClient.swift
+++ b/{{cookiecutter.app_name}}/Features/Sources/App/AppClient.swift
@@ -12,25 +12,24 @@ import Foundation
import NetworkPlatform
import PersistentPlatform
-public struct AppClient {
- public var prepare: (()) async -> Void
- public var save: @Sendable (_ request: Domain.Product) async throws -> Void
- public var product: @Sendable (_ request: Int) async throws -> Domain.Product?
-}
+struct AppClient {
+ var getProduct: any ProductUseCaseType
+ var saveProduct: any SaveProductUseCaseType
+ var prepareCoreData: any PrepareCoreDataUseCaseType
-extension AppClient {
- private init(
- _ prepare: PrepareCoreDataUseCase, productUseCase: ProductUseCase,
- saveProduct: SaveProductUseCase
+ init(
+ _ prepare: PrepareCoreDataUseCase,
+ getProductUseCase: ProductUseCase,
+ saveProductUseCase: SaveProductUseCase
) {
- self.prepare = prepare.execute(input:)
- self.save = saveProduct.execute(input:)
- self.product = productUseCase.execute(input:)
+ self.prepareCoreData = prepare
+ self.getProduct = getProductUseCase
+ self.saveProduct = saveProductUseCase
}
}
extension DependencyValues {
- public var appClient: AppClient {
+ var appClient: AppClient {
get { self[AppClient.self] }
set { self[AppClient.self] = newValue }
}
@@ -39,17 +38,17 @@ extension DependencyValues {
extension AppClient: DependencyKey {
public static var liveValue = AppClient(
PrepareCoreDataUseCase(repository: PreparePersistentRepository.live),
- productUseCase: ProductUseCase(repository: RemoteProductRepository.live),
- saveProduct: SaveProductUseCase(
+ getProductUseCase: ProductUseCase(repository: RemoteProductRepository.live),
+ saveProductUseCase: SaveProductUseCase(
repository: PersistentProductRepository.live))
public static var testValue = AppClient(
PrepareCoreDataUseCase(repository: PreparePersistentRepository.live),
- productUseCase: ProductUseCase(repository: RemoteProductRepository.stubbed),
- saveProduct: SaveProductUseCase(
+ getProductUseCase: ProductUseCase(repository: RemoteProductRepository.stubbed),
+ saveProductUseCase: SaveProductUseCase(
repository: PersistentProductRepository.live))
public static var previewValue = AppClient(
PrepareCoreDataUseCase(repository: PreparePersistentRepository.live),
- productUseCase: ProductUseCase(repository: RemoteProductRepository.stubbed),
- saveProduct: SaveProductUseCase(
+ getProductUseCase: ProductUseCase(repository: RemoteProductRepository.stubbed),
+ saveProductUseCase: SaveProductUseCase(
repository: PersistentProductRepository.live))
}
diff --git a/{{cookiecutter.app_name}}/Features/Sources/App/AppFeature.swift b/{{cookiecutter.app_name}}/Features/Sources/App/AppFeature.swift
index 96c0235..b9c670f 100644
--- a/{{cookiecutter.app_name}}/Features/Sources/App/AppFeature.swift
+++ b/{{cookiecutter.app_name}}/Features/Sources/App/AppFeature.swift
@@ -50,12 +50,12 @@ public struct AppFeature: FeatureReducer {
switch viewAction {
case .onAppear:
return .run { send in
- await appClient.prepare(Void())
+ try? await appClient.prepareCoreData()
await send(
.internal(
.productResponse(
Result {
- try await appClient.product(1)
+ try await appClient.getProduct(input: 2)
})))
}
case .showSheet:
@@ -69,7 +69,7 @@ public struct AppFeature: FeatureReducer {
case .save:
return .run { [product = state.product] send in
do {
- try await appClient.save(product!)
+ try await appClient.saveProduct(input: product!)
} catch {
}
diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 9effde1..6ac1f5b 100644
--- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -75,7 +75,7 @@
{
"identity" : "swift-composable-architecture",
"kind" : "remoteSourceControl",
- "location" : "https://github.com/pointfreeco/swift-composable-architecture",
+ "location" : "git@github.com:pointfreeco/swift-composable-architecture.git",
"state" : {
"revision" : "cf967a28a8605629559533320d604168d733fc9c",
"version" : "1.8.0"