Last active
January 18, 2022 18:56
-
-
Save zafarivaev/35144912395d745076034ff9e27016b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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