Last active
April 2, 2024 09:36
-
-
Save yannxou/0949e553c3329513ade94d3559d66ee1 to your computer and use it in GitHub Desktop.
Combine: One-shot subscriptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credit: https://www.apeth.com/UnderstandingCombine/subscribers/subscribersoneshot.html | |
var cancellable: AnyCancellable? | |
cancellable = pub.sink(receiveCompletion: {_ in | |
cancellable?.cancel() | |
}) { image in | |
self.imageView.image = image | |
} | |
// Or just subscribe to the Subscribers.Sink: | |
// https://stackoverflow.com/questions/61216852/whats-the-difference-between-sink-and-subscribers-sink | |
pub.subscribe( | |
Subscribers.Sink( | |
receiveCompletion: { _ in }, | |
receiveValue: { _ in } | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment