diff --git a/EasyCrypto.xcodeproj/project.pbxproj b/EasyCrypto.xcodeproj/project.pbxproj index 51b2fc4..2b7af0d 100644 --- a/EasyCrypto.xcodeproj/project.pbxproj +++ b/EasyCrypto.xcodeproj/project.pbxproj @@ -477,7 +477,6 @@ isa = PBXGroup; children = ( A81742C2297E593800023B28 /* EasyCryptoApp.swift */, - A8D4A114299E45D300C11107 /* AppDependencyContainer.swift */, 0250EA6F29B27F4200AA6040 /* AppDependencyContainer + Injection.swift */, ); path = App; @@ -515,6 +514,14 @@ path = Coordinator; sourceTree = ""; }; + 02B004542B518B0D00AB7B6C /* DIManager */ = { + isa = PBXGroup; + children = ( + A8D4A114299E45D300C11107 /* AppDependencyContainer.swift */, + ); + path = DIManager; + sourceTree = ""; + }; 02B22A8629CC476800A04929 /* Persistance */ = { isa = PBXGroup; children = ( @@ -833,6 +840,7 @@ A8D4A10A299E0DFA00C11107 /* Base */, A803DFB7297E918900357A7F /* Theme */, A803DFCD297E93F600357A7F /* Support */, + 02B004542B518B0D00AB7B6C /* DIManager */, 02B22A8629CC476800A04929 /* Persistance */, A803DFBA297E91BF00357A7F /* Core */, A803DFBB297E91C600357A7F /* Data */, @@ -1103,6 +1111,8 @@ Base, ); mainGroup = A81742B6297E593800023B28; + packageReferences = ( + ); productRefGroup = A81742C0297E593800023B28 /* Products */; projectDirPath = ""; projectRoot = ""; diff --git a/EasyCrypto/App/EasyCryptoApp.swift b/EasyCrypto/App/EasyCryptoApp.swift index fddd0ec..7414e47 100644 --- a/EasyCrypto/App/EasyCryptoApp.swift +++ b/EasyCrypto/App/EasyCryptoApp.swift @@ -14,13 +14,15 @@ struct EasyCryptoApp: App { let coreDataManager = CoreDataManager.preview + @StateObject var viewModel: MainViewModel = MainViewModel() + init() { DIContainer.shared.registration() } var body: some Scene { WindowGroup { - MainCoordinator(viewModel: MainViewModel()) + MainCoordinator(viewModel: viewModel) .environment(\.managedObjectContext, coreDataManager.container.viewContext) } } diff --git a/EasyCrypto/App/AppDependencyContainer.swift b/EasyCrypto/DIManager/AppDependencyContainer.swift similarity index 100% rename from EasyCrypto/App/AppDependencyContainer.swift rename to EasyCrypto/DIManager/AppDependencyContainer.swift diff --git a/EasyCrypto/Presentation/CoinDetail/Coordinator/CoinDetailCoordinator.swift b/EasyCrypto/Presentation/CoinDetail/Coordinator/CoinDetailCoordinator.swift index 7cc19f1..3d7fca7 100644 --- a/EasyCrypto/Presentation/CoinDetail/Coordinator/CoinDetailCoordinator.swift +++ b/EasyCrypto/Presentation/CoinDetail/Coordinator/CoinDetailCoordinator.swift @@ -10,7 +10,7 @@ import Combine struct CoinDetailCoordinator: CoordinatorProtocol { - @StateObject var viewModel: CoinDetailViewModel + @ObservedObject var viewModel: CoinDetailViewModel @State var activeRoute: Destination? = Destination(route: .first(url: nil)) @State var transition: Transition? let id: String diff --git a/EasyCrypto/Presentation/Main/Coordinator/MainCoordinator.swift b/EasyCrypto/Presentation/Main/Coordinator/MainCoordinator.swift index 0da4ef6..d489ec0 100644 --- a/EasyCrypto/Presentation/Main/Coordinator/MainCoordinator.swift +++ b/EasyCrypto/Presentation/Main/Coordinator/MainCoordinator.swift @@ -9,8 +9,9 @@ import SwiftUI import Combine struct MainCoordinator: CoordinatorProtocol { + + @StateObject var viewModel: MainViewModel - @StateObject var viewModel = MainViewModel() @State var activeRoute: Destination? = Destination(route: .first(item: MarketsPrice())) @State var transition: Transition? @@ -31,15 +32,15 @@ struct MainCoordinator: CoordinatorProtocol { } var mainView: MainView { - return MainView(viewModel: viewModel) + MainView(viewModel: viewModel) } } extension MainCoordinator { struct Destination: DestinationProtocol { - + var route: MainView.Routes - + @ViewBuilder var content: some View { switch route { @@ -49,7 +50,7 @@ extension MainCoordinator { CoinDetailCoordinator(viewModel: CoinDetailViewModel(), id: data) } } - + var transition: Transition { switch route { case .first: return .push diff --git a/EasyCrypto/Presentation/Main/View/SortView.swift b/EasyCrypto/Presentation/Main/View/SortView.swift index ec50e12..ae1eefe 100644 --- a/EasyCrypto/Presentation/Main/View/SortView.swift +++ b/EasyCrypto/Presentation/Main/View/SortView.swift @@ -9,7 +9,7 @@ import SwiftUI struct SortView: View { - @State var viewModel: MainViewModel + @ObservedObject var viewModel: MainViewModel @State var viewState: Bool = false var body: some View {