Juanpe / Swift-VIPER-Module

Xcode template for VIPER Architecture written in Swift 4
542 stars 113 forks source link

Controller is held by Router? #17

Open zhihuitang opened 6 years ago

zhihuitang commented 6 years ago

In my understanding, the Router should hold Presenter only, not Controller.

But in your VIPER framework, the controller is held by Router.

class LoginRouter: LoginWireframeProtocol {

    weak var viewController: UIViewController?

    static func createModule() -> UIViewController {
        // Change to get view from storyboard if not using progammatic UI
        let view = LoginViewController(nibName: nil, bundle: nil)
        let interactor = LoginInteractor()
        let router = LoginRouter()
        let presenter = LoginPresenter(interface: view, interactor: interactor, router: router)

        view.presenter = presenter
        interactor.presenter = presenter
        router.viewController = view

        return view
    }
}
SergeyPetrachkov commented 6 years ago

another approach is to have Router methods signatures like :

func showMyModule(from view: UIViewController, moduleOut: ModuleOutParameters)

and pass view from presenter.

Moreover, Router should not be responsible for creating and setting up modules. It's Assembly layer responsibility. Each modue should have Assembly that handles dependency injections and stuff.