NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

The right way to present view controller using coordinators?

Forums > Swift

Hi, guys! Just watched Paul's tutorial about coordinators:

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 Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.