Urlsession.Shared.Datataskpublisher Not Working on iOS 13.3

Why is sink never called in my combine pipeline?

dataTaskPublisher(for: urlRequest) will send values asynchronously. When program execution leaves your current scope, there are no more references to your pipeline and ARC destroys your pipeline before the network request has completed.

Your pipeline returns a Cancellable. Either assign that Cancellable directly to an instance variable or add the store(in:) operator to your pipeline.

Also worth mentioning is that if you mess around with Combine pipelines in an Xcode playground, your pipelines may live longer than you'd expect because the Playground tries to be smart about holding on to references for the sake of making experimentation easier. See this answer for an async example you can run in a playground, even though it applies neither of the fixes I mentioned.

.sink method from Combine not working on iOS 13.3

This might be due to fixed releasing of cancelable (just an assumption). Try the following

var cancellables = Set<AnyCancellable>()

init() {
$segmentedSelected
.debounce(for: .seconds(0.1), scheduler: DispatchQueue.main)
.sink(receiveValue: self.segmentedChanged(indexValue:))
.store(in: &cancellables)
}


Related Topics



Leave a reply



Submit