promotion
Powerful debugging in Xcode,
no code changes or 3rd party frameworks required.

subscribe(on:) vs receive(on:)

In this post, instead of looking into the basics of multi-threading with Combine, we are going to have a look at the difference between subscribe(on:) and receive(on:) specifically. We’re going to look at a typical subscription chain starting with a root publisher, a couple of operators, and a subscriber at the end. We’ll look into more diagrams and some example code of how subscribe(on:) and receive(on:) affect subscriptions. subscribe(on:) subscribe(on:) sets the scheduler on which you’d like the current subscription to be “managed” on. …

Posted on

Binding a list with multiple sections and different cells

Today’s post showcases another real-life use case of using CombineDataSources, namely binding a list to a table view with multiple sections using different cell types. In my last post Binding a simple list to a UITableView we had a look at binding a list of data elements to a table view. It’s pretty simple to bind a plain table view when you have a coherent list of elements. In this post I’m gonna show some code on how to bind a list to a table with multiple sections that also needs to use different cell types for the different sections. …

Posted on

Binding a simple list to a UITableView

While still keep improving the current version of CombineDataSources I tought it’d be nice to post few articles on the current API design along with some code samples. This would be nice in order to get some feedback and to try putting some of the code in context. CombineDataSources Introduction RxSwiftCommunity’s excellent RxDataSources allows developers to reactively bind data to table and collection views. It uses a lot of the underlaying structure of RxSwift and it’s very powerful. …

Posted on

An assert operator: assertMaxSubscriptions()

While I keep working on CombineDataSources I’ve faced some of the differences between RxSwift and Combine and those are slowing me down a bit. For example: in RxSwift when dealing with UI I’d usually use shareReplayLatestWhileConnected() - this operator shares an observable and emits the latest value to all subscribers downstream. In Combine there is currently a share() operator which does a similar thing but does not “replay” the latest value. …

Posted on

Debug logging with CombinePrintout

Logging is a really powerful way to debug code, especially if it’s asynchronous code that runs in a time sensitive way so stepping through the debugger is a pain. In Simple custom Combine operators I wrote about how to create an operator that logs to the system Console app in just few lines. After playing with Combine some more I went ahead and created a micro framework called “CombinePrintout” that adds few convenient methods to Combine allowing you to quickly print information about your subscriptions. …

Posted on

Building a custom `sample` operator

In Simple custom Combine operators I spoke about how you can cheaply create your own custom Combine operator without the need to create a new custom Publisher type. In this post I’d like to show how this kind of “cheap” operators could actually be quite complex and useful; still being created only by creatively combining existing operators. Let’s look at sample(_)… The sample operator rxmarbles.com is a marveleous website where you can find visual and interactive presentations of a multitude of reactive operators (based in their implementation in RxJS). …

Posted on

Simple custom Combine operators

Creating simple custom operators is very straightforward in Combine. As long as your custom operator can be expressed via combining existing operators you don’t need to create a new publisher type - you can simply extend the Publisher protocol with your own custom operator. Let’s try quickly creating one now. Extending Publisher You can extend Publisher like any other protocol in Swift. For this post I’ll create a debugging operator that writes logs to the system console. …

Posted on