SwiftEventBus alternatives and similar libraries
Based on the "EventBus" category.
Alternatively, view SwiftEventBus alternatives based on common mentions on social networks and blogs.
-
Bolts
Bolts is a collection of low-level libraries designed to make developing mobile apps easier. -
promises
Promises is a modern framework that provides a synchronization construct for Swift and Objective-C. -
SwiftTask
Promise + progress + pause + cancel + retry for Swift. -
BrightFutures
Write great asynchronous code in Swift using futures and promises -
Hydra
⚡️ Lightweight full-featured Promises, Async & Await Library in Swift -
Bolts-Swift
Bolts is a collection of low-level libraries designed to make developing mobile apps easier. -
FutureKit
A Swift based Future/Promises Library for IOS and OS X. -
Promise
A Promise library for Swift, based partially on Javascript's A+ spec -
SwiftNotificationCenter
A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety -
When
:alarm_clock: A lightweight implementation of Promises in Swift -
NoticeObserveKit
NoticeObserveKit is type-safe NotificationCenter wrapper. -
RWPromiseKit
A light-weighted Promise library for Objective-C -
Promis
The easiest Future and Promises framework in Swift. No magic. No boilerplate. -
Continuum
NotificationCenter based Lightweight UI / AnyObject binder. -
TopicEventBus
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic. -
Futures
Lightweight promises for iOS, macOS, tvOS, watchOS, and Linux -
FutureLib
FutureLib is a pure Swift 2 library implementing Futures & Promises inspired by Scala. -
Bluebird.swift
Promise/A+, Bluebird inspired, implementation in Swift 5
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of SwiftEventBus or a related project?
README
SwiftEventBus
Allows publish-subscribe-style communication between components without requiring the components to explicitly be aware of each other
Features
- [x] simplifies the communication between components
- [x] decouples event senders and receivers
- [x] avoids complex and error-prone dependencies and life cycle issues
- [x] makes your code simpler
- [x] is fast
- [x] is tiny
- [x] Thread-safe
Installation
Cocoapods
pod 'SwiftEventBus', :tag => '5.0.1', :git => 'https://github.com/cesarferreira/SwiftEventBus.git'
Carthage
github "cesarferreira/SwiftEventBus" == 5.0.1
Versions
5.+
forswift 5
3.+
forswift 4.2
2.+
forswift 3
1.1.0
forswift 2.2
Usage
1 - Prepare subscribers
Subscribers implement event handling methods that will be called when an event is received.
SwiftEventBus.onMainThread(target, name: "someEventName") { result in
// UI thread
}
// or
SwiftEventBus.onBackgroundThread(target, name:"someEventName") { result in
// API Access
}
2 - Post events
Post an event from any part of your code. All subscribers matching the event type will receive it.
SwiftEventBus.post("someEventName")
--
Eventbus with parameters
Post event
SwiftEventBus.post("personFetchEvent", sender: Person(name:"john doe"))
Expecting parameters
SwiftEventBus.onMainThread(target, name:"personFetchEvent") { result in
let person : Person = result.object as Person
println(person.name) // will output "john doe"
}
Posting events from the BackgroundThread to the MainThread
Quoting the official Apple documentation:
Regular notification centers deliver notifications on the thread in which the notification was posted
Regarding this limitation, @nunogoncalves implemented the feature and provided a working example:
@IBAction func clicked(sender: AnyObject) {
count++
SwiftEventBus.post("doStuffOnBackground")
}
@IBOutlet weak var textField: UITextField!
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
SwiftEventBus.onBackgroundThread(self, name: "doStuffOnBackground") { notification in
println("doing stuff in background thread")
SwiftEventBus.postToMainThread("updateText")
}
SwiftEventBus.onMainThread(self, name: "updateText") { notification in
self.textField.text = "\(self.count)"
}
}
//Perhaps on viewDidDisappear depending on your needs
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
SwiftEventBus.unregister(self)
}
--
Unregistering
Remove all the observers from the target
SwiftEventBus.unregister(target)
Remove observers of the same name from the target
SwiftEventBus.unregister(target, "someEventName")