SwiftNotificationCenter alternatives and similar libraries
Based on the "EventBus" category.
Alternatively, view SwiftNotificationCenter alternatives based on common mentions on social networks and blogs.
-
promises
Promises is a modern framework that provides a synchronization construct for Swift and Objective-C. -
Bolts-Swift
Bolts is a collection of low-level libraries designed to make developing mobile apps easier. -
TopicEventBus
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.
WorkOS - The modern identity platform for B2B SaaS
* 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 SwiftNotificationCenter or a related project?
README
A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety.
Type Safe
No more
userInfo
dictionary and Downcasting, just deliver the concrete type value to the observer.Thread Safe
You can
register
,notify
,unregister
in any thread without crash and data corruption.Memory Safety
SwiftNotificationCenter
store the observer as a zeroing-weak reference. No crash and no need tounregister
manually.
It's simple, safe, lightweight and easy to use for one-to-many
communication.
Usage
Define protocol and observer:
protocol Update {
func updateTitle(title: String)
}
extension ViewController: Update {
func updateTitle(title: String) {
self.titleLabel.text = title
}
}
let vc = ViewController()
Register:
Broadcaster.register(Update.self, observer: vc)
Broadcast:
Broadcaster.notify(Update.self) {
$0.updateTitle("new title")
}
Unregister:
Broadcaster.unregister(Update.self, observer: self)
Compare with NSNotificationCenter
:
For example, handle UIKeyboardWillShowNotification
@objc func handleKeyboardNotification(notification: NSNotification) {
guard notification.name == NSNotification.Name.UIKeyboardWillShow
else { return }
guard let beginFrame = (notification
.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
else { return }
guard let endFrame = (notification
.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
else { return }
// use beginFrame, endFrame
}
SwiftNotificationCenter
way:
/*
If you want to observe the system built in notifications like this.
You can declare a protocol and the relevant method, and use a singleton as a mediator to observe system's notification, then notify our observers.
Please check the refactor example in SwiftNotificationCenterExample Project.
*/
func UIKeyboardWillShow(beginFrame: CGRect, endFrame: CGRect) {
}
Installation
CocoaPods:
pod 'SwiftNotificationCenter'
Carthage:
github "100mango/SwiftNotificationCenter"
Manually:
Just copy source files in the SwiftNotificationCenter folder into your project.
License
SwiftNotificationCenter
is under the MIT license.
*Note that all licence references and agreements mentioned in the SwiftNotificationCenter README section above
are relevant to that project's source code only.