Created
August 19, 2021 03:16
-
-
Save zmcartor/817b08571e184a35b43af89f101b8850 to your computer and use it in GitHub Desktop.
Revisions
-
zmcartor created this gist
Aug 19, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ import UIKit struct FrontScreenViewmodel { var hello = "there" } // Builds the ViewControllers, and injects the ViewModels class Factory { let viewModelFactory = ViewModelFactory() let mainStack: UINavigationController func createFrontScreen(withStack: UINavigationController? = nil) -> UIViewController { // create a new Coordinator, pass in our factory let coor = FrontScreenCoordinator(withStack: withStack ?? mainStack, factory: self) let viewmodel = viewModelFactory.FrontScreenViewmodel() return FrontScreenViewController(withViewModel: viewmodel, coordinator: coor) } init(withStack: UINavigationController) { mainStack = withStack } } // Handles Core Data, Networing, etc assembly of documentModel into ViewModel class ViewModelFactory { func FrontScreenViewmodel() -> FrontScreenViewmodel { // pass in other things like interactors, etc. return FrontScreenViewmodel() } } class FrontScreenCoordinator { // encapsulates the Routes this VC can trigger. Each VC has unique coordinator. func gotoNext() {} func goBack() {} func showStore(withId: Int) { let vc = factory.createFrontScreen() stack.pushViewController(vc, animated: true) } private let factory: Factory private let stack: UINavigationController init(withStack: UINavigationController, factory: Factory) { self.stack = withStack self.factory = factory } } class FrontScreenViewController: UIViewController { private let coordinator: FrontScreenCoordinator private let viewModel: FrontScreenViewmodel init(withViewModel: FrontScreenViewmodel, coordinator: FrontScreenCoordinator) { self.coordinator = coordinator self.viewModel = withViewModel super.init() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }