An example of how to create a custom subscriber in Combine

custom-subscriber-in-combine

Here’s an example of how to create a custom subscriber in Combine

SegmentSink

In this project, you could replace the term sink with segmentSink to see how it affects the user interface.

(1...50000).publisher.sink(
    receiveCompletion: { completion in
        print("Completion: \(completion)")
        _ = self.cancellables.map { $0.cancel() }
    },
    receiveValue: { value in
        print("Receive value: \(value)")
        DispatchQueue.main.async {
            self.textLabel.text = String(value)
            self.progressBar.progress = Float(value)/50000.0
        }
    }
).store(in: &cancellables)

Using publisher.sink

Using publisher.segmentSink

GitHub

View Github