.send() and .sink() do not seem to work anymore for PassthroughSubject in Xcode 11 Beta 5

var body: some View {
       
        let publisher = PassthroughSubject<string, never="">(
       
        publisher.sink { (str) in
            print(str)
        }
        return Button("OK") {
            publisher.send("Test")
        }
    }


"Test" should be printed in the console when the Button is pressed, but it's not. The event is not send through the publisher.

Any idea what happened with PassthroughSubject in Xcode 11 Beta 5 ?

Seeing the same issue... anyone found a way to recover this functionality?

I noticed that publisher sinks seem to unsubscribe when the cancellable gets destroyed - which is immediately if the cancellable is never assigned!

This code is a start, but I think it may unsubscribe when it's containing scope is destroyed (eg. if it's in a function, when the function completes).

let cancelable = publisher.sink{...}

You may need to create the cancelable in a scope that will last longer in order for things to work as you expect.


In a view such as the one in your code snippet, it will be difficult to create the cancelable that lasts because the view is a struct. In your case, you probably want to use onReceive.

It's not an issue, you're just using the framework wrong if you don't store a reference to the AnyCancellable that the sink method returns.

var body: some View { var bag = Set<AnyCancellable>() let publisher = PassthroughSubject<string, never="">(

    publisher.sink { (str) in
        print(str)
    }.store(in:&bag)
    return Button("OK") {
        publisher.send("Test")
    }
}
.send() and .sink() do not seem to work anymore for PassthroughSubject in Xcode 11 Beta 5
 
 
Q