Awesome Open Source
Awesome Open Source


Language Language Language Language

Allows publish-subscribe-style communication between components without requiring the components to explicitly be aware of each other


  • [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



pod 'SwiftEventBus', :tag => '5.1.0', :git => ''


github "cesarferreira/SwiftEventBus" == 5.1.0


  • 5.+ for swift 5
  • 3.+ for swift 4.2
  • 2.+ for swift 3
  • 1.1.0 for swift 2.2


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."someEventName")


Eventbus with parameters

Post event"personFetchEvent", sender: Person(name:"john doe"))

Expecting parameters

SwiftEventBus.onMainThread(target, name:"personFetchEvent") { result in
    let person : Person = result.object as Person
    println( // 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) {

 @IBOutlet weak var textField: UITextField!

 var count = 0

 override func viewDidLoad() {

     SwiftEventBus.onBackgroundThread(self, name: "doStuffOnBackground") { notification in
         println("doing stuff in background thread")

     SwiftEventBus.onMainThread(self, name: "updateText") { notification in
         self.textField.text = "\(self.count)"

//Perhaps on viewDidDisappear depending on your needs
override func viewWillDisappear(_ animated: Bool) {




Remove all the observers from the target


Remove observers of the same name from the target

SwiftEventBus.unregister(target, "someEventName")

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Swift (95,626
Ios (19,329
Notifications (2,683
Thread (931
Communication (786
Eventbus (483
Related Projects