Using RxSwift with StreamChat v2.x

LAST EDIT Jul 21 2021
The new v3 SDK does not currently have RxSwift integration. Stay tuned!

Rx is a generic abstraction of computation expressed through Observable interface. RxSwift is the Swift implementation of Rx.

Stream uses RxSwift to enable easy composition of asynchronous operations and event/data streams. You can check their quick start guide if you're not familiar with RxSwift.

Using RxSwift with StreamChat Swift SDK


By default the official Swift API client handles I/O operation using traditional callback-style. RxSwift is supported by installing our Core library called StreamChatCore. When you use StreamChatCore you can access rx style methods from the client. For instance, Client.shared.addDevice Rx counter part is Client.shared.rx.addDevice.

To use RxSwift, you should have the StreamChatCore dependency installed. If you're using StreamChat, it's already available since StreamChat depends on it. If you're only using StreamChatClient, then you'll need to add StreamChatCore to your Podfile like so:

In the file you want to use RxSwift,

You can access rx subset as such:

For example, to add device, you can use both callback way and Rx way:

As another example, let's look at creating a channel:

Debugging RxSwift


Here's the official Debugging guide.

You can just put .debug("my debug label") to any Observable to enable debug logging.


will print