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
class ValueConsumer { | |
private var subscription1: AnyCancellable? | |
private var subscription2: AnyCancellable? | |
private var subscription3: AnyCancellable? | |
private let mySubject = CurrentValueSubject<Int, Never>(0) | |
private var myVar: Int = 0 | |
func consumeValues(publisher1, ...) { | |
subscription1 = publisher1 |
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
struct Podcast: Equatable { | |
let title: String | |
let previewImage: UIImage | |
let podcastURL: URL | |
} |
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
protocol PodcastsService { | |
func loadPodcasts(completion: (Result<[Podcast], Error>) -> Void) | |
} |
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
class PodcastsViewModel { | |
private let service: PodcastsService | |
let podcasts = BehaviorRelay<[Podcast]>(value: []) | |
func loadPodcasts() { | |
service.loadPodcasts { [weak self] result in | |
let records = result.value ?? [] | |
self?.podcasts.accept(records) |
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
class PodcastCell: UITableViewCell { | |
func populate(podcast: Podcast) { | |
textLabel?.text = podcast.title | |
imageView?.image = podcast.previewImage | |
} | |
} |
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
class PodcastsViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
var viewModel: PodcastsViewModel! | |
var disposeBag = DisposeBag() | |
func viewDidLoad() { | |
super.viewDidLoad() | |
let cellIdentifier = String(describing: PodcastCell.self) | |
tableView.register(PodcastCell.self, forCellReuseIdentifier: cellIdentifier) |
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
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) |
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
class PodcastsViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
@IBOutlet weak var errorMessageLabel: UILabel! | |
@IBOutlet weak var indicatorView: UIActivityIndicatorView! | |
var viewModel: PodcastsViewModel! | |
var disposeBag = DisposeBag() | |
func viewDidLoad() { | |
super.viewDidLoad() |
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
enum Loadable<Value> { | |
case notRequested | |
case isLoading | |
case loaded(Value) | |
case failed(Error) | |
} |
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
class PodcastsViewModel { | |
private let service: PodcastsService | |
let podcasts = BehaviorRelay<Loadable<[Podcast]>>(value: .notRequested) | |
func loadPodcasts() { | |
podcasts.accept(.isLoading) | |
service.loadPodcasts { [weak self] result in | |
switch result { |
OlderNewer