swiftcoordinator-pattern

Swift 5 Applying coordinator pattern results in blank screen


In my AppDelegate I have this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    window = UIWindow(frame: UIScreen.main.bounds)

    let rootNavController = UINavigationController()
    appCoordinator = AppCoordinator(withRootController: rootNavController)
    appCoordinator.start()

    window?.rootViewController = rootNavController
    window?.makeKeyAndVisible()

return true
}

And then in my AppCoordinator, I have this:

final class AppCoordinator {

  var rootController: UINavigationController
  let initialViewController: UIViewController

  init(withRootController: UINavigationController) {
    self.rootController = withRootController
    initialViewController = InitialViewController()
  }
}

extension AppCoordinator: Coordinator {

    func start() {
        //rootController.show(rootController, sender: self)
        rootController.pushViewController(initialViewController, animated: false)
    }
}

But when I run it I only see a black screen. This pattern used to work for me in Swift 3, but I can't figure out what I'm doing incorrectly with Swift 5.

I've deleted Main.storyboard and erased all references to it from info.plist as well.


Solution

  • Figured this out.

    Apple had moved quite a bit of launch logic to SceneDelegate from AppDelegate, so I just moved my code there, and it worked.