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

Bridge from Combine to AsyncSequence - the code (p. 2)

Yesterday I wrote about AsyncSequence, AsyncStream and a simple plan how to bridge (or proxy) Combine publishers to the new asynchronous sequences APIs - Bridge from Combine to AsyncSequence - the plan (part 1). Today let’s put together the code as planned and see if that’s going to work out so we can easily use publishers as async sequences. CombineAsyncStream setup I’ll create a new type called CombineAsyncStream and make it conform to AsyncSequence. …

Posted on

Bridge from Combine to AsyncSequence - the plan (p. 1)

Previously, I wrote about actors in Actors part 1 and Actors part 2; this time I’m going to cover how to write a Combine operator to proxy a Combine publisher into an async sequence that you can iterate over by using a simple for loop. Note: The current version of Xcode 13 is beta 2 and I’m going to be using the latest swift.org toolchain nightly snapshot in order to make use of AsyncStream. …

Posted on

Swift Actors: A practical example, part 2

In my previous post Swift Actors: A practical example, part 1 I covered how I got a Swift.org toolchain from trunk, enabled support for the currently experimental support for structured concurrency, and created a thread-safe cache in few lines of Swift code. If you missed part 1, definitely do read it first as this post builds upon the code I already covered there. » When I wrapped up writing part 1, I was looking at my new cache actor and I started wondering “What about Combine? …

Posted on

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

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. Here’s a summary of what’s new. …

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