Created
January 19, 2022 17:31
-
-
Save zafarivaev/32b9b8ec164aa231acd3497e90edd521 to your computer and use it in GitHub Desktop.
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
private func bindAvatarToImageView() { | |
getAvatarFromTheServer() | |
.handleEvents(receiveSubscription: { [weak self] in | |
print("Subscribed", $0) | |
self?.state = .loading | |
}, receiveOutput: { | |
print("Got image", $0) | |
}, receiveCompletion: { | |
print("Completion", $0) | |
}) | |
.delay(for: 1, scheduler: DispatchQueue.global()) | |
.retry(3) | |
.replaceError(with: UIImage(named: "placeholder")!) | |
.receive(on: DispatchQueue.main) | |
.sink(receiveCompletion: { completion in | |
switch completion { | |
case .finished: | |
print("Finished") | |
} | |
}, receiveValue: { [weak self] image in | |
self?.imageView.image = image | |
self?.state = .loadedSuccessfully | |
}) | |
.store(in: &cancellables) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment