Skip to content

Instantly share code, notes, and snippets.

@gringoireDM
Last active May 22, 2019 18:54
Show Gist options
  • Save gringoireDM/bb3a09ecce31dd6437fd79ff346df197 to your computer and use it in GitHub Desktop.
Save gringoireDM/bb3a09ecce31dd6437fd79ff346df197 to your computer and use it in GitHub Desktop.
An example of AppDelegate using MERLin
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var moduleManager: BaseModuleManager = BaseModuleManager()
var router: SimpleRouter!
lazy var eventsListeners: [AnyEventsListening] = {
[
ConsoleLogEventsListener(),
RoutingEventsListener(withRouter: router)
]
}()
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
router = SimpleRouter(withFactory: moduleManager)
moduleManager.addEventsListeners(eventsListeners)
eventsListeners.forEach { $0.registerToEvents(for: self) }
return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.rootViewController = router.rootViewController(forLaunchOptions: launchOptions)
window?.makeKeyAndVisible()
_events.onNext(.didFinishLaunching)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment