Update README.md
If you want to get all events of an application, you can get events from UIApplication.sendEvent(_:). But, following implementations are needed to get events from it.
UIApplication.sendEvent(_:)
/* MyApplication.swift */ class MyApplication: UIApplication { override sendEvent(_ event: UIEvent) { super.sendEvent(event) print(event) } }
/* main.swift */ private let applicationClassName: String = { #if DEBUG return NSStringFromClass(MyApplication.self) #else return NSStringFromClass(UIApplication.self) #endif }() UIApplicationMain( CommandLine.argc, UnsafeMutableRawPointer(CommandLine.unsafeArgv) .bindMemory( to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)), applicationClassName, NSStringFromClass(AppDelegate.self) )
/* AppDelegate.swift */ // @UIApplicationMain <- comment out class AppDelegate: UIResponder, UIApplicationDelegate { ... }
Degu makes them easy!!
Degu
This is an example. There are only 2 implementations what you have to.
ApplicationProxy.shared.delegate
ApplicationProxyDelegate
import Degu class AppDelegate: UIResponder, ApplicationDelegate { ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. #if DEBUG ApplicationProxy.shared.delegate = self #endif ... return true } ... } extension AppDelegate: ApplicationProxyDelegate { func applicationProxy(_ proxy: ApplicationProxy, didSendEvent event: UIEvent) { print(event) } }
In addition, you can get lifecycle method call of all ViewControllers.
func applicationProxy(_ proxy: ApplicationProxy, didCallLifeCycle lifeCycle: ViewControllerLifeCycle, ofViewController viewController: UIViewController) { print("ViewController = \(viewController)") print("LifeCycle = \(lifeCycle)") }
+(void)load and +(void)initialize are not permitted by Swift.
You can override +(void)load and +(void)initialize in Extension of RuntimeHandler.
+(void)load
+(void)initialize
extension RuntimeHandler { open override class func handleLoad() { // do something } open override class func handleInitialize() { // do something } }
⚠️ handleLoad and handleInitialize are not called Subclass of RuntimeHandler. It only works in Extension of RuntimeHandler.
handleLoad
handleInitialize
If you’re using Carthage, simply add Degu to your Cartfile:
Cartfile
github "cats-oss/Degu"
Degu is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Degu'
If you’re using Swift Package Manager, simply add Degu to your Package.swift:
Package.swift
dependencies: [ .package(url: "https://github.com/cats-oss/Degu", from: "0.2.0") ]
Degu is available under the MIT license. See the LICENSE file for more info.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
If you want to get all events of an application, you can get events from
UIApplication.sendEvent(_:)
. But, following implementations are needed to get events from it.Degu
makes them easy!!Usage
1. ApplicationProxy
This is an example. There are only 2 implementations what you have to.
ApplicationProxy.shared.delegate
ApplicationProxyDelegate
In addition, you can get lifecycle method call of all ViewControllers.
2. Override load or initialize method
+(void)load and +(void)initialize are not permitted by Swift.
You can override
+(void)load
and+(void)initialize
in Extension of RuntimeHandler.⚠️
handleLoad
andhandleInitialize
are not called Subclass of RuntimeHandler. It only works in Extension of RuntimeHandler.Installation
Carthage
If you’re using Carthage, simply add Degu to your
Cartfile
:CocoaPods
Degu is available through CocoaPods. To install it, simply add the following line to your Podfile:
Swift Package Manager
If you’re using Swift Package Manager, simply add Degu to your
Package.swift
:Requirements
License
Degu is available under the MIT license. See the LICENSE file for more info.