Skip to content

Instantly share code, notes, and snippets.

@zafarivaev
Last active January 18, 2022 18:56
Show Gist options
  • Save zafarivaev/35144912395d745076034ff9e27016b5 to your computer and use it in GitHub Desktop.
Save zafarivaev/35144912395d745076034ff9e27016b5 to your computer and use it in GitHub Desktop.
import UIKit
import Combine
...
class ViewController: UIViewController {
...
override func viewDidLoad() {
...
getAvatarFromTheServer()
// 1
.handleEvents(receiveSubscription: { print("Subscribed", $0)},
receiveOutput: { print("Got image", $0)},
receiveCompletion: { print("Completion", $0)})
// 2
.receive(on: DispatchQueue.main)
// 3
.sink(receiveCompletion: { completion in
switch completion {
case let .failure(error):
print("Finished with error: \(error)")
case .finished:
print("Finished")
}
}, receiveValue: { [weak self] image in
// 4
self?.imageView.image = image
})
.store(in: &cancellables)
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment