Skip to content

Instantly share code, notes, and snippets.

@helbertgs
Created February 21, 2020 22:36
Show Gist options
  • Save helbertgs/e67c101d3ff540c71c066580630037eb to your computer and use it in GitHub Desktop.
Save helbertgs/e67c101d3ff540c71c066580630037eb to your computer and use it in GitHub Desktop.
import UIKit
typealias Provider = NSObject & UIApplicationDelegate
class ComposedProvider: Provider {
// MARK: Property(ies).
private var providers: [Provider]
// MARK: Constructor(s).
init(with providers: [Provider] = []) {
self.providers = providers
}
// MARK: Funtion(s).
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
print(#function)
let result = self.providers.reduce(true, { result, provider in
result && provider.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? false
})
return result
}
func applicationWillTerminate(_ application: UIApplication) {
self.providers.forEach {
$0.applicationWillTerminate?(application)
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
self.providers.forEach {
$0.applicationDidBecomeActive?(application)
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
self.providers.forEach {
$0.applicationDidEnterBackground?(application)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
self.providers.forEach {
$0.applicationWillEnterForeground?(application)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment