Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Created March 22, 2020 14:00
Show Gist options
  • Select an option

  • Save cipolleschi/469d453fa13caed458e3d83af114956f to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/469d453fa13caed458e3d83af114956f to your computer and use it in GitHub Desktop.
Dice Roller AppDelegate
import Katana
import Tempura
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RootInstaller {
var window: UIWindow?
var store: Store<AppState, AppDependencies>?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 1. Initialize the store
self.store = Store<AppState, AppDependencies>(
interceptors: [],
stateInitializer: AppState.init)
// 2. create the window
let window = UIWindow()
self.window = window
// 3. Start the navigation
self.store?.dependencies?.navigator.start(
using: self,
in: self.window!,
at: "initialScreen"
)
window.makeKeyAndVisible()
return true
}
// 4. Required by the RootInstaller. It's the function invoked
// by Tempura when it has to replace the rootViewController
// It's the first step of the navigation.
func installRoot(identifier: RouteElementIdentifier, context: Any?, completion: @escaping Navigator.Completion) -> Bool {
if identifier == "initialScreen" {
let vc = UIViewController()
vc.view.backgroundColor = .green
self.window?.rootViewController = vc
completion()
return true
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment