From 6a5c51389dcd14c49137c855097a99e67f8c0bb3 Mon Sep 17 00:00:00 2001 From: jinwoong16 Date: Sat, 2 Nov 2024 15:27:42 +0900 Subject: [PATCH] Revert "Feature/di profile view" --- Kabinett.xcodeproj/project.pbxproj | 40 -------- .../Application/DIContainer/DIContainer.swift | 57 ----------- .../Application/DIContainer/Injected.swift | 21 ---- .../DIContainer/InjectionKey.swift | 18 ---- .../DIContainer/Keys/ServiceKeys.swift | 33 ------- .../DIContainer/Keys/UseCaseKeys.swift | 29 ------ Kabinett/Application/DIContainer/Module.swift | 19 ---- Kabinett/Application/KabinettApp.swift | 96 +------------------ .../View/Profile/AccountSettingsView.swift | 2 +- .../View/Profile/ProfileSettingsView.swift | 2 +- .../View/Profile/ProfileView.swift | 13 +-- .../View/Profile/SettingsView.swift | 6 +- 12 files changed, 8 insertions(+), 328 deletions(-) delete mode 100644 Kabinett/Application/DIContainer/DIContainer.swift delete mode 100644 Kabinett/Application/DIContainer/Injected.swift delete mode 100644 Kabinett/Application/DIContainer/InjectionKey.swift delete mode 100644 Kabinett/Application/DIContainer/Keys/ServiceKeys.swift delete mode 100644 Kabinett/Application/DIContainer/Keys/UseCaseKeys.swift delete mode 100644 Kabinett/Application/DIContainer/Module.swift diff --git a/Kabinett.xcodeproj/project.pbxproj b/Kabinett.xcodeproj/project.pbxproj index 9ad34ac..b83bc8d 100644 --- a/Kabinett.xcodeproj/project.pbxproj +++ b/Kabinett.xcodeproj/project.pbxproj @@ -91,12 +91,6 @@ 7FCAE2BC2C73157C00228FA7 /* LetterWritingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FCAE2BB2C73157C00228FA7 /* LetterWritingView.swift */; }; 8314013F2C69C34500F601FB /* Letter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8314013E2C69C34500F601FB /* Letter.swift */; }; 832C72672C71CF7B0071E8D0 /* SignUpUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832C72662C71CF7B0071E8D0 /* SignUpUseCase.swift */; }; - 83358CAD2CB2621400D1DD00 /* Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CAC2CB2621400D1DD00 /* Module.swift */; }; - 83358CAF2CB2643400D1DD00 /* DIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CAE2CB2643400D1DD00 /* DIContainer.swift */; }; - 83358CB12CB2644400D1DD00 /* Injected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CB02CB2644400D1DD00 /* Injected.swift */; }; - 83358CB32CB2645300D1DD00 /* InjectionKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CB22CB2645300D1DD00 /* InjectionKey.swift */; }; - 83358CB82CB2673000D1DD00 /* ServiceKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CB72CB2673000D1DD00 /* ServiceKeys.swift */; }; - 83358CBC2CB2674900D1DD00 /* UseCaseKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83358CBB2CB2674900D1DD00 /* UseCaseKeys.swift */; }; 839CE0F72C644BEF003635F3 /* KabinettApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839CE0F62C644BEF003635F3 /* KabinettApp.swift */; }; 839CE0F92C644BEF003635F3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839CE0F82C644BEF003635F3 /* ContentView.swift */; }; 839CE0FE2C644BF0003635F3 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 839CE0FD2C644BF0003635F3 /* Preview Assets.xcassets */; }; @@ -228,12 +222,6 @@ 7FCAE2BB2C73157C00228FA7 /* LetterWritingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LetterWritingView.swift; sourceTree = ""; }; 8314013E2C69C34500F601FB /* Letter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Letter.swift; sourceTree = ""; }; 832C72662C71CF7B0071E8D0 /* SignUpUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpUseCase.swift; sourceTree = ""; }; - 83358CAC2CB2621400D1DD00 /* Module.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Module.swift; sourceTree = ""; }; - 83358CAE2CB2643400D1DD00 /* DIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DIContainer.swift; sourceTree = ""; }; - 83358CB02CB2644400D1DD00 /* Injected.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injected.swift; sourceTree = ""; }; - 83358CB22CB2645300D1DD00 /* InjectionKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InjectionKey.swift; sourceTree = ""; }; - 83358CB72CB2673000D1DD00 /* ServiceKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceKeys.swift; sourceTree = ""; }; - 83358CBB2CB2674900D1DD00 /* UseCaseKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UseCaseKeys.swift; sourceTree = ""; }; 83949C892C71BC0F0080D72C /* DefaultProfileUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultProfileUseCase.swift; sourceTree = ""; }; 839CE0F32C644BEF003635F3 /* Kabinett.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kabinett.app; sourceTree = BUILT_PRODUCTS_DIR; }; 839CE0F62C644BEF003635F3 /* KabinettApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KabinettApp.swift; sourceTree = ""; }; @@ -461,27 +449,6 @@ path = SignUpUseCase; sourceTree = ""; }; - 83358CAB2CB2620600D1DD00 /* DIContainer */ = { - isa = PBXGroup; - children = ( - 83358CB42CB2652F00D1DD00 /* Keys */, - 83358CAC2CB2621400D1DD00 /* Module.swift */, - 83358CAE2CB2643400D1DD00 /* DIContainer.swift */, - 83358CB02CB2644400D1DD00 /* Injected.swift */, - 83358CB22CB2645300D1DD00 /* InjectionKey.swift */, - ); - path = DIContainer; - sourceTree = ""; - }; - 83358CB42CB2652F00D1DD00 /* Keys */ = { - isa = PBXGroup; - children = ( - 83358CB72CB2673000D1DD00 /* ServiceKeys.swift */, - 83358CBB2CB2674900D1DD00 /* UseCaseKeys.swift */, - ); - path = Keys; - sourceTree = ""; - }; 8366B6EF2C65ECC50021FAE0 /* Entity */ = { isa = PBXGroup; children = ( @@ -650,7 +617,6 @@ 838697C72C64B7FB00E76230 /* Application */ = { isa = PBXGroup; children = ( - 83358CAB2CB2620600D1DD00 /* DIContainer */, 839CE0F62C644BEF003635F3 /* KabinettApp.swift */, ); path = Application; @@ -943,7 +909,6 @@ AFCFDFC42C7C3F2A00BEFFDF /* FirestoreLetterManager.swift in Sources */, 577157052C75DD9900E21162 /* Writer.swift in Sources */, 04DEC0FE2C7EDB1100D289EA /* KabinettNumberFormatter.swift in Sources */, - 83358CAD2CB2621400D1DD00 /* Module.swift in Sources */, 83F0D6872C7072DB001B8733 /* FirestoreWriterManager.swift in Sources */, 53FC6B842C90204D00E7D9A8 /* CloseButtonView.swift in Sources */, 577156FD2C7584E000E21162 /* NavigationBarView.swift in Sources */, @@ -962,11 +927,7 @@ 83CA92AB2C8160CB00DFB68B /* Publisher+.swift in Sources */, 7F6CE9C42C6B50050074568E /* ImagePickerViewModel.swift in Sources */, 534C67B72C7FF85700F0C175 /* LetterContentView.swift in Sources */, - 83358CB12CB2644400D1DD00 /* Injected.swift in Sources */, 7FCAE2BA2C73102900228FA7 /* ImageDetailView.swift in Sources */, - 83358CB82CB2673000D1DD00 /* ServiceKeys.swift in Sources */, - 83358CBC2CB2674900D1DD00 /* UseCaseKeys.swift in Sources */, - 83358CAF2CB2643400D1DD00 /* DIContainer.swift in Sources */, 04DEC0E72C6C6C7300D289EA /* ProfileView.swift in Sources */, 53A482DA2C6C6F2D00F00A9A /* LetterBoxCell.swift in Sources */, 53A482D42C6B4E8600F00A9A /* LetterBoxView.swift in Sources */, @@ -1011,7 +972,6 @@ 57966B9E2C7DB267008D650B /* Extension+TextField.swift in Sources */, 7F78684C2C78B41A0083D204 /* ImagePickerView.swift in Sources */, 7F23AD6C2C7432B8007E1F28 /* LetterCompletionView.swift in Sources */, - 83358CB32CB2645300D1DD00 /* InjectionKey.swift in Sources */, AFB88B592C89410600E79F90 /* DefaultWriteLetterUseCase.swift in Sources */, 53FC6B8A2C90221600E7D9A8 /* LetterHelper.swift in Sources */, 57ED94FA2C84AFAC00A6F187 /* LetterWriteModel.swift in Sources */, diff --git a/Kabinett/Application/DIContainer/DIContainer.swift b/Kabinett/Application/DIContainer/DIContainer.swift deleted file mode 100644 index fa9301e..0000000 --- a/Kabinett/Application/DIContainer/DIContainer.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// DIContainer.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -final class DIContainer { - static var shared = DIContainer() - private var modules: [String: Module] = [:] - - private init() {} - - deinit { modules.removeAll() } -} - -extension DIContainer { - func register(with module: Module) { - modules[module.name] = module - } - - func resolve(for type: Any.Type?) -> T { - let name = type.map { String(describing: $0) } ?? String(describing: T.self) - if let resolved = modules[name]?.resolved as? T { - return resolved - } - - guard let dependency = modules[name]?.resolve() as? T else { - fatalError("dependency \(T.self) not resolved.") - } - modules[name]?.resolved = dependency - - return dependency - } -} - -extension DIContainer { - @resultBuilder - struct ModuleBuilder { - static func buildBlock(_ components: Module...) -> [Module] { - components - } - static func buildBlock(_ component: Module) -> Module { - component - } - } - - func register(@ModuleBuilder _ modules: () -> [Module]) { - modules().forEach { register(with: $0) } - } - - func register(@ModuleBuilder _ module: () -> Module) { - register(with: module()) - } -} diff --git a/Kabinett/Application/DIContainer/Injected.swift b/Kabinett/Application/DIContainer/Injected.swift deleted file mode 100644 index 715ab1b..0000000 --- a/Kabinett/Application/DIContainer/Injected.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// Injected.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -@propertyWrapper -final class Injected { - private var storage: Value - - var wrappedValue: Value { - storage - } - - init(_ key: K.Type) where K: InjectionKey, Value == K.Value { - storage = key.currentValue - } -} diff --git a/Kabinett/Application/DIContainer/InjectionKey.swift b/Kabinett/Application/DIContainer/InjectionKey.swift deleted file mode 100644 index 3cc435b..0000000 --- a/Kabinett/Application/DIContainer/InjectionKey.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// InjectionKey.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -protocol InjectionKey { - associatedtype Value -} - -extension InjectionKey { - static var currentValue: Value { - DIContainer.shared.resolve(for: Self.self) - } -} diff --git a/Kabinett/Application/DIContainer/Keys/ServiceKeys.swift b/Kabinett/Application/DIContainer/Keys/ServiceKeys.swift deleted file mode 100644 index ea46fa1..0000000 --- a/Kabinett/Application/DIContainer/Keys/ServiceKeys.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// ServiceKeys.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -// MARK: - The Keys of Services -/// Note. -/// All objects of data layer are concret type. -/// In contrast, the objects of other layers -/// are existential type. -struct AuthManagerKey: InjectionKey { - typealias Value = AuthManager -} - -struct FirestoreWriterManagerKey: InjectionKey { - typealias Value = FirestoreWriterManager -} - -struct FirestoreLetterManagerKey: InjectionKey { - typealias Value = FirestoreLetterManager -} - -struct FirestorageWriterManagerKey: InjectionKey { - typealias Value = FirestorageWriterManager -} - -struct FirestorageLetterManagerKey: InjectionKey { - typealias Value = FirestorageLetterManager -} diff --git a/Kabinett/Application/DIContainer/Keys/UseCaseKeys.swift b/Kabinett/Application/DIContainer/Keys/UseCaseKeys.swift deleted file mode 100644 index 4527bae..0000000 --- a/Kabinett/Application/DIContainer/Keys/UseCaseKeys.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// UseCaseKeys.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -// MARK: - The Keys of UseCases -struct SignUpUseCaseKey: InjectionKey { - typealias Value = SignUpUseCase -} - -struct ProfileUseCaseKey: InjectionKey { - typealias Value = ProfileUseCase -} - -struct WriteLetterUseCaseKey: InjectionKey { - typealias Value = WriteLetterUseCase -} - -struct LetterBoxUseCaseKey: InjectionKey { - typealias Value = LetterBoxUseCase -} - -struct ImportLetterUseCaseKey: InjectionKey { - typealias Value = ImportLetterUseCase -} diff --git a/Kabinett/Application/DIContainer/Module.swift b/Kabinett/Application/DIContainer/Module.swift deleted file mode 100644 index cc426e0..0000000 --- a/Kabinett/Application/DIContainer/Module.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// Module.swift -// Kabinett -// -// Created by jinwoong Kim on 10/6/24. -// - -import Foundation - -final class Module { - let name: String - let resolve: () -> Any - var resolved: Any? = nil - - init(_ name: T.Type, _ resolve: @escaping () -> Any) { - self.name = String(describing: name) - self.resolve = resolve - } -} diff --git a/Kabinett/Application/KabinettApp.swift b/Kabinett/Application/KabinettApp.swift index a9d184b..a870df7 100644 --- a/Kabinett/Application/KabinettApp.swift +++ b/Kabinett/Application/KabinettApp.swift @@ -13,6 +13,7 @@ import FirebaseFirestore @main struct KabinettApp: App { + // MARK: - LetterBox Flow @StateObject private var letterViewModel: LetterViewModel @StateObject private var letterBoxViewModel: LetterBoxViewModel @@ -55,10 +56,6 @@ struct KabinettApp: App { Firestore.firestore().settings = settings #endif - // MARK: Register Dependencies - KabinettApp.registerServices() - KabinettApp.registerUseCases() - // MARK: - Service Dependencies let writerManager = FirestoreWriterManager() let writerStorageManager = FirestorageWriterManager() @@ -185,95 +182,4 @@ struct KabinettApp: App { .environmentObject(previewLetterViewModel) } } - - // MARK: Register Services - private static func registerServices() { - // MARK: Register Firestorage Services - DIContainer.shared.register { - Module(FirestorageWriterManagerKey.self) { - FirestorageWriterManager() - } - Module(FirestorageLetterManagerKey.self) { - FirestorageLetterManager() - } - } - - // MARK: Register Firestore Services - DIContainer.shared.register { - Module(FirestoreWriterManagerKey.self) { - FirestoreWriterManager() - } - Module(FirestoreLetterManagerKey.self) { - @Injected(FirestorageLetterManagerKey.self) - var firestorageLetterManager: FirestorageLetterManager - - return FirestoreLetterManager(storageManager: firestorageLetterManager) - } - } - - // MARK: Register Firestore Authenticate Service - DIContainer.shared.register { - Module(AuthManagerKey.self) { - @Injected(FirestoreWriterManagerKey.self) - var firestoreWriterManager: FirestoreWriterManager - - return AuthManager(writerManager: firestoreWriterManager) - } - } - } - - // MARK: - Register UseCases - private static func registerUseCases() { - @Injected(AuthManagerKey.self) var authManager: AuthManager - - @Injected(FirestoreWriterManagerKey.self) - var firestoreWriterManager: FirestoreWriterManager - - @Injected(FirestoreLetterManagerKey.self) - var firestoreLetterManager: FirestoreLetterManager - - @Injected(FirestorageWriterManagerKey.self) - var firestorageWriterManager: FirestorageWriterManager - - @Injected(FirestorageLetterManagerKey.self) - var firestorageLetterManager: FirestorageLetterManager - - DIContainer.shared.register { - Module(SignUpUseCaseKey.self) { - DefaultSignUpUseCase( - authManager: authManager, - writerManager: firestoreWriterManager - ) - } - Module(ProfileUseCaseKey.self) { - DefaultProfileUseCase( - authManager: authManager, - writerManager: firestoreWriterManager, - writerStorageManager: firestorageWriterManager - ) - } - Module(WriteLetterUseCaseKey.self) { - DefaultWriteLetterUseCase( - authManager: authManager, - writerManager: firestoreWriterManager, - letterManager: firestoreLetterManager, - letterStorageManager: firestorageLetterManager - ) - } - Module(LetterBoxUseCaseKey.self) { - DefaultLetterBoxUseCase( - letterManager: firestoreLetterManager, - authManager: authManager - ) - } - Module(ImportLetterUseCaseKey.self) { - DefaultImportLetterUseCase( - authManager: authManager, - writerManager: firestoreWriterManager, - letterManager: firestoreLetterManager, - letterStorageManager: firestorageLetterManager - ) - } - } - } } diff --git a/Kabinett/Presentation/View/Profile/AccountSettingsView.swift b/Kabinett/Presentation/View/Profile/AccountSettingsView.swift index 44b62d8..5417965 100644 --- a/Kabinett/Presentation/View/Profile/AccountSettingsView.swift +++ b/Kabinett/Presentation/View/Profile/AccountSettingsView.swift @@ -8,7 +8,7 @@ import SwiftUI struct AccountSettingsView: View { - @ObservedObject var viewModel: ProfileViewModel + @EnvironmentObject var viewModel: ProfileViewModel @Environment(\.dismiss) var dismiss @State private var showLogoutAlert = false @State private var showAccountDeletionAlert = false diff --git a/Kabinett/Presentation/View/Profile/ProfileSettingsView.swift b/Kabinett/Presentation/View/Profile/ProfileSettingsView.swift index e053400..b3a8dac 100644 --- a/Kabinett/Presentation/View/Profile/ProfileSettingsView.swift +++ b/Kabinett/Presentation/View/Profile/ProfileSettingsView.swift @@ -10,7 +10,7 @@ import PhotosUI import Kingfisher struct ProfileSettingsView: View { - @ObservedObject var viewModel: ProfileViewModel + @EnvironmentObject var viewModel: ProfileViewModel @Environment(\.dismiss) var dismiss var body: some View { diff --git a/Kabinett/Presentation/View/Profile/ProfileView.swift b/Kabinett/Presentation/View/Profile/ProfileView.swift index c4778b1..354f28a 100644 --- a/Kabinett/Presentation/View/Profile/ProfileView.swift +++ b/Kabinett/Presentation/View/Profile/ProfileView.swift @@ -9,16 +9,7 @@ import SwiftUI import Kingfisher struct ProfileView: View { - @StateObject private var viewModel: ProfileViewModel - - init() { - @Injected(ProfileUseCaseKey.self) - var profileUseCase: ProfileUseCase - - self._viewModel = StateObject( - wrappedValue: ProfileViewModel(profileUseCase: profileUseCase) - ) - } + @EnvironmentObject var viewModel: ProfileViewModel var body: some View { NavigationStack { @@ -90,7 +81,7 @@ struct ProfileView: View { } } .navigationDestination(isPresented: $viewModel.showSettingsView) { - SettingsView(viewModel: viewModel) + SettingsView() } } } diff --git a/Kabinett/Presentation/View/Profile/SettingsView.swift b/Kabinett/Presentation/View/Profile/SettingsView.swift index c42d2db..69dca2b 100644 --- a/Kabinett/Presentation/View/Profile/SettingsView.swift +++ b/Kabinett/Presentation/View/Profile/SettingsView.swift @@ -8,7 +8,7 @@ import SwiftUI struct SettingsView: View { - @ObservedObject var viewModel: ProfileViewModel + @EnvironmentObject var viewModel: ProfileViewModel @Environment(\.dismiss) var dismiss let horizontalPadding: CGFloat = UIScreen.main.bounds.width * 0.06 @@ -17,7 +17,7 @@ struct SettingsView: View { ZStack { Color.background.ignoresSafeArea(.all) VStack(alignment: .leading) { - NavigationLink(destination: ProfileSettingsView(viewModel: viewModel)) { + NavigationLink(destination: ProfileSettingsView()) { HStack{ Text("프로필 설정") .fontWeight(.medium) @@ -36,7 +36,7 @@ struct SettingsView: View { } .buttonStyle(PlainButtonStyle()) - NavigationLink(destination: AccountSettingsView(viewModel: viewModel)) { + NavigationLink(destination: AccountSettingsView()) { HStack{ Text("계정 설정") .fontWeight(.medium)