Skip to content

Instantly share code, notes, and snippets.

@gahntpo
Last active June 21, 2020 07:45
Show Gist options
  • Save gahntpo/2df05d84ecdc7d66967aec26c6af3f54 to your computer and use it in GitHub Desktop.
Save gahntpo/2df05d84ecdc7d66967aec26c6af3f54 to your computer and use it in GitHub Desktop.
Placing the NavigationController in the environment
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
//add the NavigationController like so:
let contentView = ContentView().environmentObject(NavigationController())
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment