Group Group Group Group Group Group Group Group Group

Errata for Combine: Asynchronous Programming with Swift 3rd Edition

Creating this topic to catch any typos and bugs in the 3rd Edition of Combine: Asynchronous Programming with Swift.

Chapter 2 URL

Section Hello Future seems to have missed the declaration of the below statement

You also add a subscriptions set in which you’ll store the subscriptions to the future in the example.

This can cause confusion when following the section. Should this be made available in the chapter code snippets ?

On a second note, this code does not seem to produce any output on the playground page

example(of: "Future") {
    var subscriptions: Set<AnyCancellable>? = []
    func futureIncrement(
        integer: Int,
        afterDelay delay: TimeInterval) -> Future<Int, Never> {
        print("Original 1")
        return Future<Int, Never> { promise in
            print("Original 2")
   .now() + delay) {
                promise(.success(integer + 1))
    let future = futureIncrement(integer: 1, afterDelay: 3)
        .sink(receiveCompletion: { print($0) },
              receiveValue: { print($0) })
        .store(in: &subscriptions!)

I just see

——— Example of: Future ———

Am I missing something to be running this on the playground ?

Stumbled upon the same result, for the sake of curiosity I’ve opened the final playground and surprise this code is commented LOL.
Googled this : “combine future dispatchqueue”

if the code is written outside the example(of:action:) function everything works as expected, I’m guessing the subscription is released before the async code is executed.

1 Like

Thanks for the response, yes you are right. Another way to make this work is to move the declaration of

var subscriptions: Set<AnyCancellable>? = []

to outside the example(of:action:) function so that this is retained.

Thanks, I’ll have a look - maybe we moved the line during the last edit :+1:t3:

Oh, btw - the link you’ve included in this thread points to the old edition of the book, have you had a look at the update from this year? Combine: Asynchronous Programming with Swift |

Thank, yes I did start the earlier version. I am still on that version of XCode :slight_smile:
btw its great to have different versions of the book available for compatibility etc :+1:t2:

Chapter 1 - Operators

I think the middle box should be <String, Error> <String, Never>

hey @omran_k , why do you think so?

@icanzilb shouldn’t an Operator input type be the output of the previous Operator? The first Operator has a output type of <String, Error>

Oh I see, you’re right - they’ve been updating the diagrams recently - this one needs to be fixed. Thanks for spotting this

Hi there,
I’m reading your fantastic book and I think I’ve found a little typo.
On the section I in the chapter 2.1 “Getting started” seems to be written “plauyground” instead “playground”.
Thank you for your work