{"id":1093,"url":"https://github.com/cesarferreira/SwiftEventBus","last_synced_at":"2025-08-06T13:32:27.740Z","repository":{"id":26966497,"uuid":"30429843","full_name":"cesarferreira/SwiftEventBus","owner":"cesarferreira","description":"A publish/subscribe EventBus optimized for iOS","archived":false,"fork":false,"pushed_at":"2021-03-17T11:42:00.000Z","size":155,"stargazers_count":1125,"open_issues_count":12,"forks_count":110,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-08-01T19:51:59.916Z","etag":null,"topics":["communication","eventbus","ios","notifications","pub-sub","thread"],"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/cesarferreira.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":"2015-02-06T19:45:05.000Z","updated_at":"2025-07-29T10:41:02.000Z","dependencies_parsed_at":"2023-01-14T10:01:10.390Z","dependency_job_id":null,"html_url":"https://github.com/cesarferreira/SwiftEventBus","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/cesarferreira/SwiftEventBus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarferreira%2FSwiftEventBus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarferreira%2FSwiftEventBus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarferreira%2FSwiftEventBus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarferreira%2FSwiftEventBus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cesarferreira","download_url":"https://codeload.github.com/cesarferreira/SwiftEventBus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesarferreira%2FSwiftEventBus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268830884,"owners_count":24314086,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["communication","eventbus","ios","notifications","pub-sub","thread"],"created_at":"2024-01-05T20:15:38.777Z","updated_at":"2025-08-06T13:32:27.452Z","avatar_url":"https://github.com/cesarferreira.png","language":"Swift","funding_links":[],"categories":["EventBus","Libs","Swift","Events [🔝](#readme)"],"sub_categories":["Getting Started","Events","Other free courses","Linter"],"readme":"# SwiftEventBus\n[![Language](https://img.shields.io/badge/Swift-5.0-green.svg?style=flat)](http://cocoapods.org/pods/SwiftEventBus)\n[![Language](https://img.shields.io/badge/Swift-4.2-green.svg?style=flat)](http://cocoapods.org/pods/SwiftEventBus)\n[![Language](https://img.shields.io/badge/Swift-3.0-green.svg?style=flat)](http://cocoapods.org/pods/SwiftEventBus)\n[![Language](https://img.shields.io/badge/Swift-2.2-green.svg?style=flat)](http://cocoapods.org/pods/SwiftEventBus)\n\nAllows publish-subscribe-style communication between components without requiring the components to explicitly be aware of each other\n\n## Features\n\n- [x] simplifies the communication between components\n- [x] decouples event senders and receivers\n- [x] avoids complex and error-prone dependencies and life cycle issues\n- [x] makes your code simpler\n- [x] is fast\n- [x] is tiny\n- [x] Thread-safe\n\n## Installation\n\n### Cocoapods\n\n```bash\npod 'SwiftEventBus', :tag =\u003e '5.1.0', :git =\u003e 'https://github.com/cesarferreira/SwiftEventBus.git'\n```\n\n### Carthage\n```bash\ngithub \"cesarferreira/SwiftEventBus\" == 5.1.0\n```\n\n### Versions\n\n- `5.+` for `swift 5`\n- `3.+` for `swift 4.2`\n- `2.+` for `swift 3`\n- `1.1.0` for `swift 2.2`\n\n## Usage\n### 1 - Prepare subscribers ###\n\nSubscribers implement event handling methods that will be called when an event is received.\n\n```swift\nSwiftEventBus.onMainThread(target, name: \"someEventName\") { result in\n    // UI thread\n}\n\n// or\n\nSwiftEventBus.onBackgroundThread(target, name:\"someEventName\") { result in\n    // API Access\n}\n```\n\n### 2 - Post events ###\n\nPost an event from any part of your code. All subscribers matching the event type will receive it.\n\n```swift\nSwiftEventBus.post(\"someEventName\")\n```\n\n--\n\n### Eventbus with parameters\n\nPost event\n\n```swift\nSwiftEventBus.post(\"personFetchEvent\", sender: Person(name:\"john doe\"))\n```\n\nExpecting parameters\n```swift\nSwiftEventBus.onMainThread(target, name:\"personFetchEvent\") { result in\n    let person : Person = result.object as Person\n    println(person.name) // will output \"john doe\"\n}\n```\n\n### Posting events from the BackgroundThread to the MainThread\n\nQuoting the official Apple [documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html):\n\u003e Regular notification centers deliver notifications on the thread in which the notification was posted\n\n\nRegarding this limitation, [@nunogoncalves](https://github.com/nunogoncalves) implemented the feature and provided a working example:\n\n```swift\n\n@IBAction func clicked(sender: AnyObject) {\n     count++\n     SwiftEventBus.post(\"doStuffOnBackground\")\n }\n\n @IBOutlet weak var textField: UITextField!\n\n var count = 0\n\n override func viewDidLoad() {\n     super.viewDidLoad()\n\n     SwiftEventBus.onBackgroundThread(self, name: \"doStuffOnBackground\") { notification in\n         println(\"doing stuff in background thread\")\n         SwiftEventBus.postToMainThread(\"updateText\")\n     }\n\n     SwiftEventBus.onMainThread(self, name: \"updateText\") { notification in\n         self.textField.text = \"\\(self.count)\"\n     }\n}\n\n//Perhaps on viewDidDisappear depending on your needs\noverride func viewWillDisappear(_ animated: Bool) {\n    super.viewWillDisappear(animated)\n\n    SwiftEventBus.unregister(self)\n}\n```\n--\n\n\n## Unregistering\n\nRemove all the observers from the target\n```swift\nSwiftEventBus.unregister(target)\n```\nRemove observers of the same name from the target\n```swift\nSwiftEventBus.unregister(target, \"someEventName\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesarferreira%2FSwiftEventBus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesarferreira%2FSwiftEventBus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesarferreira%2FSwiftEventBus/lists"}