Event Bus equivalent in iOS

With Swift you can use SwiftEventBus. It's just a nice wrapper around NSNotificationCenter and DispatchQueue.

Register to an event:

SwiftEventBus.onMainThread(target, name: "someEventName") { result in
    // UI thread
    // Do something when the event occurr
}

Trigger an event:

SwiftEventBus.post("someEventName")

And if you need to customize it, the source code is short, clear and easy to understand.


I think you can use NSNotificationCenter for this, I read your comment about it is one-to-many and it's true by default but you can specify from which object do you want to receive messages like this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(someSelector:)
                                             name:@"MyPersonalNotification"
                                           object:someOtherObject];

Here you will receive the MyPersonalNotification in someSelector: only when someOtherObject post it. This made the communication one-to-one.

Also you can use the Key-Value Observing API but I personally found it somewhat uncomfortable.