NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

The right way to present view controller using coordinators?

Forums > Swift

Hi, guys! Just watched Paul's tutorial about coordinators: https://www.hackingwithswift.com/articles/175/advanced-coordinator-pattern-tutorial-ios

In video code examples he only pushed view controllers, what if we need to present controller modally? What is the right way to do that?

My solution is this, but I don't think that it is the right way:

class MainCoordinator: Coordinator {
    var childCoordinators = [Coordinator]()
    var navigationController: UINavigationController
    weak var presenter: UIViewController?

    init(navigationController: UINavigationController) {
        self.navigationController = navigationController
    }

    convenience init(presenter: UIViewController, navigationController: UINavigationController) {
        self.init(navigationController: navigationController)
        self.presenter = presenter
    }

    func start() {        
        let vc = MainAssembly().createMainModule(coordinator: self)
        presenter?.present(vc, animated: true)
    }
}

   

Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.