Skip to content

Commit

Permalink
Merge pull request #10 from erikdrobne/fix/example-app-view-hierarchy
Browse files Browse the repository at this point in the history
Pass navigation controller to existing window instead of creating new…
  • Loading branch information
erikdrobne authored May 4, 2023
2 parents f406b99 + 77bc712 commit 56a0651
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ struct SwiftUICoordinatorExampleApp: App {

final class SceneDelegate: NSObject, UIWindowSceneDelegate {

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
guard let window = (scene as? UIWindowScene)?.windows.first else {
return
}

let coordinator = ShapesCoordinator(startRoute: .shapes)
window = UIWindow(windowScene: windowScene)
/// Assign root coordinator's navigation controller
window?.rootViewController = coordinator.navigationController
window?.makeKeyAndVisible()
window.rootViewController = coordinator.navigationController
window.makeKeyAndVisible()

try? coordinator.start()
}
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ final class SceneDelegate: NSObject, UIWindowSceneDelegate {
var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
guard let window = (scene as? UIWindowScene)?.windows.first else {
return
}

let coordinator = ShapesCoordinator(startRoute: .shapes)
window = UIWindow(windowScene: windowScene)
/// Assign root coordinator's navigation controller
window?.rootViewController = coordinator.navigationController
window?.makeKeyAndVisible()
window.rootViewController = coordinator.navigationController
window.makeKeyAndVisible()

coordinator.start()
try? coordinator.start()
}
}

Expand Down

0 comments on commit 56a0651

Please sign in to comment.