Created
March 31, 2017 14:07
-
-
Save janodev/764963747c26c724d85f6bed3dcd8f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PluggableApplicationDelegate | |
@UIApplicationMain | |
class AppDelegate: PluggableApplicationDelegate | |
{ | |
override var services: [ApplicationService] { | |
return [ | |
LoggerApplicationService() | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PluggableApplicationDelegate | |
final class LoggerApplicationService: NSObject, ApplicationService | |
{ | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { | |
print("It has started!") | |
return true | |
} | |
func applicationDidEnterBackground(_ application: UIApplication) { | |
print("It has entered background") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol ApplicationService: UIApplicationDelegate {} | |
open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate | |
{ | |
public var window: UIWindow? | |
open var service s: [ApplicationService] { return [] } | |
private lazy var __services: [ApplicationService]! = { | |
return self.services | |
}() | |
@available(iOS 3.0, *) | |
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { | |
return !__services.contains(where: { service in | |
return (service.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? false) == false | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the full PluggableApplicationDelegate: https://github.com/fmo91/PluggableApplicationDelegate/blob/master/PluggableApplicationDelegate/Classes/ApplicationServicesManager.swift