Skip to content

Instantly share code, notes, and snippets.

@Ravi61
Last active March 18, 2018 10:51
Show Gist options
  • Save Ravi61/66ffa7ce560bf36fcddc3371735b01e8 to your computer and use it in GitHub Desktop.
Save Ravi61/66ffa7ce560bf36fcddc3371735b01e8 to your computer and use it in GitHub Desktop.
Code for ResponsibilityDelegator
import Foundation
import UIKit
class ResponsibilityDelegator: NSObject {
var workers: [UIApplicationDelegate]
init(workers: [UIApplicationDelegate]) {
self.workers = workers
}
}
extension ResponsibilityDelegator: UIApplicationDelegate {
@discardableResult
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
workers.forEach { worker in
_ = worker.application?(application, didFinishLaunchingWithOptions: launchOptions)
}
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
workers.forEach { worker in
worker.applicationDidBecomeActive?(application)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
workers.forEach { worker in
worker.applicationWillEnterForeground?(application)
}
}
func applicationWillResignActive(_ application: UIApplication) {
workers.forEach { worker in
worker.applicationWillResignActive?(application)
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
workers.forEach { worker in
worker.applicationDidEnterBackground?(application)
}
}
func applicationWillTerminate(_ application: UIApplication) {
workers.forEach { worker in
worker.applicationWillTerminate?(application)
}
}
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
workers.forEach { worker in
worker.application?(application, didRegister: notificationSettings)
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
workers.forEach { worker in
worker.application?(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
workers.forEach { worker in
worker.application?(application, didReceive: notification)
}
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
workers.forEach { worker in
worker.application?(application, didReceiveRemoteNotification: userInfo)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment