{"id":18269799,"url":"https://github.com/fmo91/PluggableApplicationDelegate","last_synced_at":"2025-04-04T23:31:29.308Z","repository":{"id":18058006,"uuid":"83249098","full_name":"fmo91/PluggableApplicationDelegate","owner":"fmo91","description":"Smallest AppDelegate ever by using a decoupled-services based architecture. 🛠","archived":false,"fork":false,"pushed_at":"2022-07-21T13:56:46.000Z","size":57,"stargazers_count":537,"open_issues_count":15,"forks_count":79,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-11T21:45:22.344Z","etag":null,"topics":["appdelegate","architecture","ios","services","swift"],"latest_commit_sha":null,"homepage":null,"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/fmo91.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":"2017-02-26T23:39:58.000Z","updated_at":"2024-07-11T15:50:17.000Z","dependencies_parsed_at":"2022-07-13T05:40:27.033Z","dependency_job_id":null,"html_url":"https://github.com/fmo91/PluggableApplicationDelegate","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmo91%2FPluggableApplicationDelegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmo91%2FPluggableApplicationDelegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmo91%2FPluggableApplicationDelegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmo91%2FPluggableApplicationDelegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fmo91","download_url":"https://codeload.github.com/fmo91/PluggableApplicationDelegate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247186115,"owners_count":20898095,"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":["appdelegate","architecture","ios","services","swift"],"created_at":"2024-11-05T11:37:14.613Z","updated_at":"2025-04-04T23:31:29.288Z","avatar_url":"https://github.com/fmo91.png","language":"Swift","readme":"# PluggableApplicationDelegate\n\n[![CI Status](http://img.shields.io/travis/fmo91/PluggableApplicationDelegate.svg?style=flat)](https://travis-ci.org/fmo91/PluggableApplicationDelegate)\n[![Version](https://img.shields.io/cocoapods/v/PluggableApplicationDelegate.svg?style=flat)](http://cocoapods.org/pods/PluggableApplicationDelegate)\n[![License](https://img.shields.io/cocoapods/l/PluggableApplicationDelegate.svg?style=flat)](http://cocoapods.org/pods/PluggableApplicationDelegate)\n[![Platform](https://img.shields.io/cocoapods/p/PluggableApplicationDelegate.svg?style=flat)](http://cocoapods.org/pods/PluggableApplicationDelegate)\n\n## Introduction\n`AppDelegate` is a traditional example of bad code. Lots of line of code that makes so much different things are put together in methods that are called within the application life cycle. But all of those concerns are over.\nUsing `PluggableApplicationDelegate` you decouple AppDelegate from the services that you plug to it. Each `ApplicationService` has its own life cycle that is shared with `AppDelegate`. \n\n## At a glance\nLet see some code.\nHere is how a `ApplicationService` is like:\n\n```swift\nimport Foundation\nimport PluggableApplicationDelegate\n\nfinal class LoggerApplicationService: NSObject, ApplicationService {\n    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -\u003e Bool {\n        \n        print(\"It has started!\")\n        \n        return true\n    }\n    \n    func applicationDidEnterBackground(_ application: UIApplication) {\n        print(\"It has entered background\")\n    }\n}\n```\n\nThat's all. **It is exactly the same as a AppDelegate**. Think of `ApplicationService` as sub-AppDelegates.\n\nIn `AppDelegate` you just have to inherit from PluggableApplicationDelegate to register the services.\n\n```swift\nimport UIKit\nimport PluggableApplicationDelegate\n\n@UIApplicationMain\nclass AppDelegate: PluggableApplicationDelegate {\n    \n    override var services: [ApplicationService] {\n        return [\n            LoggerApplicationService()\n        ]\n    }\n}\n```\n\nYes. That's all. Simple.\n\n## How does this work?\n\nYou may want to read my [Medium post about Pluggable App Delegate](https://medium.com/ios-os-x-development/pluggableapplicationdelegate-e50b2c5d97dd#.sz50l4d0l).\nBasically, you do an inversion of control. Instead of let AppDelegate instantiate your dependencies, perform actions at every step of its life cycle, you create objects that share the AppDelegate life cycle and plug them into your AppDelegate.\nThose objects are observers of the AppDelegate. Your AppDelegate has the only responsibility of notify them about its life cycle events.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\nPluggableApplicationDelegate requires Swift 3.0 or above.\n\n## Installation\n\nPluggableApplicationDelegate is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'PluggableApplicationDelegate'\n```\n\n## Author\n\nfmo91, ortizfernandomartin@gmail.com\n\n## License\n\nPluggableApplicationDelegate is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmo91%2FPluggableApplicationDelegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffmo91%2FPluggableApplicationDelegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmo91%2FPluggableApplicationDelegate/lists"}