Class
LaunchRouter
The root router for a napkin-based application.
@MainActor class LaunchRouter<InteractorType, ViewControllerType>
Mentioned In
Overview
LaunchRouter is a @MainActor-isolated subclass of ViewableRouter that adds the platform-specific launch(from:) entry point. Use it for the single root router of each scene.
Overview
launch(from:) performs four steps in order:
Installs the router’s view controller as the window’s root / content view controller.
Makes the window key and visible (UIKit) or key and ordered-front (AppKit).
awaits activate() on the root interactor.
awaits load(), which in turn awaits the root router’s didLoad().
Because launch(from:) is async, its callers (typically a scene delegate or App-level scene-builder) must hop into a Task.
Usage
iOS scene delegate:
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var launchRouter: LaunchRouting?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else { return }
let window = UIWindow(windowScene: windowScene)
self.window = window
Task { @MainActor in
let builder = RootBuilder(dependency: AppComponent())
let router = await builder.build()
self.launchRouter = router
await router.launch(from: window)
}
}
}
macOS app delegate:
final class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
var launchRouter: LaunchRouting?
func applicationDidFinishLaunching(_ notification: Notification) {
window = NSWindow(...)
Task { @MainActor in
let router = await RootBuilder(dependency: AppComponent()).build()
self.launchRouter = router
await router.launch(from: window)
}
}
}
See Also
LaunchRouting
See Also
ViewableRouter
Topics
Creating a LaunchRouter
Launching
Relationships
Conforms To
Inherits From