Using self, weak, and unowned in Combine

Updated with more examples on Mar 6th, 2021. One of the most often asked questions in the Combine and RxSwift slack channels is something along the lines of: Should I use self, weak, or unowned with my reactive code? Given that most operators take closures, it’s a fair question. In this post I’ll go over common scenarios for using weak, unowned or simply self and include links with more information at the bottom. …

Posted on

Owning AnyCancellable with Cancellor

Swift 5.4 officially introduces @resultBuilder, which is a way to create custom DSLs and generally create more semantic APIs (think of the way you write SwiftUI today). I wanted to play with it and create something useful for Combine developers so I thought “Would it not be handy to batch-add publisher subscriptions to an owned list of cancellables?”. I remembered back in the day I used an extension on NSObject that adds automatically a dispose bag to all objects in case you need one created by Ash Furrow and I thought I’d put together something in the same fashion. …

Posted on

5 Stranger Things you can do with Timelane at NSSpain

For my talk at NSSpain 2020 I’ve prepared a beyond-the-basics Timelane talk. I think everyone who’s heard about Timelane by now knows what it does for its simplest use case - debugging some Combine based code. However, you can do much, much more with Timelane! So for my NSSpain 2020 talk I prepared 5 little examples on how to use Timelane beyond the simplest use case. I’ve pushed all the demo apps I use in my talk to this repository: https://github. …

Posted on

How to create a custom instrument on top of Timelane!

You can easily log data in Instruments by using the functions in Apple’s os framework. All you need is to use os_log(…) and that will log data in Instruments. If you’d like to read more about this check out Recording Performance Data Apple article. Creating a real custom instrument, however, is a little more complicated as you can learn in Creating Custom Instruments WWDC2018 video and it involves XML, CLIPS, and more complex stuff. …

Posted on

Timelane - the first two weeks!

It’s been two weeks since I released Timelane and I’m really humbled by the community’s super positive response. Since much has happened since the launch, I’m writing this to give everyone a detailed update. The current versions are as follows: TimelaneCombine 1.0.4 RxTimelane 1.0.3 TimelaneCore 1.0.3 I’ve merged 18 PRs (in the 14 days since launch!) on all Timelane repos and I pushed some changes myself too. …

Posted on

Announcing: Timelane

Today I’m announcing the public release of Timelane. Timelane is a free, open source Instrument that helps you profile and debug asynchronous code. Timelane is available today on: http://timelane.tools. The Timelane Instrument leverages signpost logging and the powerful Instruments UI to help you visually inspect asynchronous subscriptions and drill down through logged events over time. Installation Install the latest build from http://timelane.tools or fork the repository on GitHub and build the app yourself. …

Posted on

Property Wrappers with Combine

In this post I’ll look into making more out of Combine code by using the newly introduced in Swift 5.1: Property Wrappers. Let’s very quickly go into what property wrappers are in general and then dive into a Combine example. Swift Property Wrappers Property wrappers are a new feature in Swift 5.1 that allows you to abstract redundant functionality around handling type properties. Property wrappers are very handy in (my experience so far 🤓 ) two ways: …

Posted on

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