-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegateComponent.swift
49 lines (39 loc) · 1.77 KB
/
AppDelegateComponent.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by Martin Hartl on 12.05.19.
//
import UIKit
public protocol AppDelegateComponent {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool
}
// Default implementations
public extension AppDelegateComponent {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) { }
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return true
}
}
public protocol AppDelegateComponentStore {
var storedComponents: [AppDelegateComponent] { get }
}
final public class AppDelegateComponentRunner {
public init() { }
public func componentStore(_ componentStore: AppDelegateComponentStore,
application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
componentStore.storedComponents.forEach {
$0.application(application,
didFinishLaunchingWithOptions: launchOptions)
}
}
public func componentStore(_ componentStore: AppDelegateComponentStore,
app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return componentStore.storedComponents.reduce(false, { result, component in
return result || component.application(app, open: url, options: options)
})
}
}