{"id":17690185,"url":"https://github.com/onmyway133/lighterappdelegate","last_synced_at":"2025-05-13T02:07:22.866Z","repository":{"id":56919773,"uuid":"49755509","full_name":"onmyway133/LighterAppDelegate","owner":"onmyway133","description":":fishing_pole_and_fish: Lighter AppDelegate by dispatching events","archived":false,"fork":false,"pushed_at":"2016-01-16T03:56:18.000Z","size":41,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T02:07:11.774Z","etag":null,"topics":["appdegate","protocol","service"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onmyway133.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-16T02:23:19.000Z","updated_at":"2021-03-11T22:34:06.000Z","dependencies_parsed_at":"2022-08-21T04:20:16.282Z","dependency_job_id":null,"html_url":"https://github.com/onmyway133/LighterAppDelegate","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FLighterAppDelegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FLighterAppDelegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FLighterAppDelegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FLighterAppDelegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onmyway133","download_url":"https://codeload.github.com/onmyway133/LighterAppDelegate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856656,"owners_count":21974582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appdegate","protocol","service"],"created_at":"2024-10-24T11:50:04.262Z","updated_at":"2025-05-13T02:07:22.842Z","avatar_url":"https://github.com/onmyway133.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LighterAppDelegate\nLighter AppDelegate by dispatching events\n\n[![CI Status](http://img.shields.io/travis/Khoa Pham/LighterAppDelegate.svg?style=flat)](https://travis-ci.org/Khoa Pham/LighterAppDelegate)\n[![Version](https://img.shields.io/cocoapods/v/LighterAppDelegate.svg?style=flat)](http://cocoapods.org/pods/LighterAppDelegate)\n[![License](https://img.shields.io/cocoapods/l/LighterAppDelegate.svg?style=flat)](http://cocoapods.org/pods/LighterAppDelegate)\n[![Platform](https://img.shields.io/cocoapods/p/LighterAppDelegate.svg?style=flat)](http://cocoapods.org/pods/LighterAppDelegate)\n\n## Usage\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Features\n\n### Dispatching events\n\n- See [Lighter AppDelegate](http://www.fantageek.com/blog/2015/10/31/lighter-appdelegate/)\n- You can use either by composition or inheritance \n- Dispatching `UIApplicationDelegate` events into specific `Service` class. We can have RootService, DebugService, AnalyticsService, ...\n\n```swift\nclass RootService : NSObject, UIApplicationDelegate {\n    func application(application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -\u003e Bool {\n\n            appDelegate().window = UIWindow(frame: UIScreen.mainScreen().bounds)\n            showHome()\n            appDelegate().window?.makeKeyAndVisible()\n\n            return true\n    }\n}\n\nextension RootService {\n    func showHome() {\n        let storyboard = UIStoryboard(name: \"Main\", bundle: nil)\n        appDelegate().window?.rootViewController = storyboard.instantiateInitialViewController()\n    }\n}\n\nextension RootService {\n    func appDelegate() -\u003e AppDelegate {\n        return UIApplication.sharedApplication().delegate as! AppDelegate\n    }\n}\n```\n\n### Composition\n\n- Initialize `Dispatcher` with your list of services\n- Dispatch interested `UIApplicationDelegate` events to `Dispatcher`\n\n```swift\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n\n    var window: UIWindow?\n    let dispatcher = Dispatcher(services: [RootService()])\n\n    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -\u003e Bool {\n        return dispatcher.application(application, didFinishLaunchingWithOptions: launchOptions)\n    }\n}\n```\n\n### Inheritance\n\n- Inherite from `LighterAppDelegate`\n- Override  `dispatcher()`\n- `LighterAppDelegate` has default implementations for `App State Changes` and `URL` events, which is suitable for common usage.\n- If you want to receive more events, add more functions inside your AppDelegate and dispatch to your `Dispatcher`\n\n```swift\n@UIApplicationMain\nclass AppDelegate: LighterAppDelegate {\n\n    var window: UIWindow?\n    let simpleDispatcher = Dispatcher(services: [RootService()])\n\n    override func dispatcher() -\u003e Dispatcher {\n        return simpleDispatcher\n    }\n\n    func applicationDidReceiveMemoryWarning(application: UIApplication) {\n        dispatcher().applicationDidReceiveMemoryWarning(application)\n    }\n}\n```\n\n### Warning\n\n- Only implement `UIApplicationDelegate` functions in case you truly need. Unnecessary functions can cause problems\n\n\u003e You've implemented -[ application:performFetchWithCompletionHandler:], but you still need to add \"fetch\" to the list of your supported UIBackgroundModes in your Info.plist.\n\n\u003e You've implemented -[ application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add \"remote-notification\" to the list of your supported UIBackgroundModes in your Info.plist.\n\n- Involving `remoteNotification` events also consider your app to [support Push Notification](https://forums.developer.apple.com/thread/15011)\n\n\u003e Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the \"aps-environment\" entitlement\n\n- I 'd like `LighterAppDelegate` to be protocol with default implementations in its extension, but for now we can't provide default implementations for Objective-C protocols.\n\n## Installation\n\nLighterAppDelegate is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"LighterAppDelegate\"\n```\n\n## Credit\nCredit goes to http://sizeof.io/service-oriented-appdelegate/\n\n## Author\n\nKhoa Pham, onmyway133@gmail.com\n\n## License\n\nLighterAppDelegate is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmyway133%2Flighterappdelegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonmyway133%2Flighterappdelegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmyway133%2Flighterappdelegate/lists"}