Skip to content

Instantly share code, notes, and snippets.

@janodev
Created March 31, 2017 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save janodev/764963747c26c724d85f6bed3dcd8f42 to your computer and use it in GitHub Desktop.
Save janodev/764963747c26c724d85f6bed3dcd8f42 to your computer and use it in GitHub Desktop.
import UIKit
import PluggableApplicationDelegate
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate
{
override var services: [ApplicationService] {
return [
LoggerApplicationService()
]
}
}
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")
}
}
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
})
}
}
@janodev
Copy link
Author

janodev commented Mar 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment