Last active
January 18, 2022 18:53
-
-
Save zafarivaev/83cd42e1d856fd8fadcb841f721a1c75 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() | |
.handleEvents(receiveSubscription: { print("Subscribed", $0)}, | |
receiveOutput: { print("Got image", $0)}, | |
receiveCompletion: { print("Completion", $0)}) | |
.retry(3) | |
.receive(on: DispatchQueue.main) | |
.sink(receiveCompletion: { completion in | |
switch completion { | |
case let .failure(error): | |
print("Finished with error: \(error)") | |
case .finished: | |
print("Finished") | |
} | |
}, receiveValue: { [weak self] image in | |
self?.imageView.image = image | |
}) | |
.store(in: &cancellables) | |
} | |
private func getAvatarFromTheServer() -> AnyPublisher<UIImage, Error> { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment