Skip to content

Instantly share code, notes, and snippets.

@yannxou
Last active April 2, 2024 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannxou/0949e553c3329513ade94d3559d66ee1 to your computer and use it in GitHub Desktop.
Save yannxou/0949e553c3329513ade94d3559d66ee1 to your computer and use it in GitHub Desktop.
Combine: One-shot subscriptions
// 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