Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

viper module without link on view

I downloaded template for viper module and it has no link on view, how do I use navigation here?

Scene Delegate

let startModule = CardsCollectionRouter.createModule()
        let navigationController = UINavigationController(rootViewController: startModule)
        window?.rootViewController = navigationController
        window?.makeKeyAndVisible()

Router

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class CardsCollectionRouter: PresenterToRouterCardsCollectionProtocol {
    
    // MARK: Static methods
    static func createModule() -> UIViewController {
        
        let viewController = CardsCollectionViewController()
        let presenter: ViewToPresenterCardsCollectionProtocol & InteractorToPresenterCardsCollectionProtocol = CardsCollectionPresenter()
        let networkService = NetworkService()
        
        viewController.presenter = presenter
        viewController.presenter?.router = CardsCollectionRouter()
        viewController.presenter?.view = viewController
        viewController.presenter?.interactor = CardsCollectionInteractor(networkService: networkService)
        viewController.presenter?.interactor?.presenter = presenter
        
        return viewController
    }
    
    func showDescription(description: CharacterModel?) {
        let descriptionVC = DescripModuleRouter.createModule(description: description)
        //How to go on next screen??
        let viewController = CardsCollectionViewController()
        viewController.navigationController?.pushViewController(descriptionVC, animated: true)
    }
    
    
}

may be I have an easy way to get a link to the view?

like view.goToAnotherScreen from router and I will have this method on my ViewController

>Solution :

You shouldn’t have to create navigation methods outside your router when using this pattern, as navigation is the router’s responsibility. You can create router.goToAnotherScreen and call it from your view controller. When creating the router, you should pass the view controller to the router and inside your router you should call viewController.navigationController?.push...

class CardsCollectionRouter: PresenterToRouterCardsCollectionProtocol {
    
    // MARK: Dependencies
    private weak var viewController: UIViewController!

    // MARK: Initialization
    init(viewController: UIViewController) {
        self.viewController = viewController
    }

    // MARK: Static methods
    static func createModule() -> UIViewController {
        let viewController = CardsCollectionViewController()
        let presenter = CardsCollectionPresenter()
        let networkService = NetworkService()
        
        viewController.presenter = presenter
        viewController.presenter?.router = CardsCollectionRouter(viewController: viewController)
        viewController.presenter?.view = viewController
        viewController.presenter?.interactor = CardsCollectionInteractor(networkService: networkService)
        viewController.presenter?.interactor?.presenter = presenter
        
        return viewController
    }
    
    func showDescription(description: CharacterModel?) {
        let descriptionVC = DescripModuleRouter.createModule(description: description)
        //How to go on next screen: Use your VC instance, which is the one your VIPER scene is controlling
        self.viewController.navigationController?.pushViewController(descriptionVC, animated: true)
    }
    
    
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading