Skip to content

Instantly share code, notes, and snippets.

@zafarivaev
Created January 19, 2022 17:31
Show Gist options
  • Save zafarivaev/32b9b8ec164aa231acd3497e90edd521 to your computer and use it in GitHub Desktop.
Save zafarivaev/32b9b8ec164aa231acd3497e90edd521 to your computer and use it in GitHub Desktop.
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