Skip to content

Instantly share code, notes, and snippets.

@nalexn
Created October 18, 2019 09:16
Show Gist options
  • Save nalexn/635f2f30990f065906b6f9cb677539de to your computer and use it in GitHub Desktop.
Save nalexn/635f2f30990f065906b6f9cb677539de to your computer and use it in GitHub Desktop.
class PodcastsViewModel {
private let service: PodcastsService
let podcasts = BehaviorRelay<[Podcast]>(value: [])
let isLoading = BehaviorRelay<Bool>(value: false)
let onError = PublishRelay<Error> = PublishRelay()
func loadPodcasts() {
isLoading.accept(true)
service.loadPodcasts { [weak self] result in
self?.isLoading.accept(false)
if let error = result.error {
self?.onError.accept(error)
}
let records = result.value ?? []
self?.podcasts.accept(records)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment