Made the "fetch()" function for the FeedListViewController view controller in the Feed framework to use Swift concurrency.

This commit is contained in:
Javier Cicchelli 2024-03-22 15:15:16 +01:00
parent a1abe1f4ae
commit 8eec6f5666
2 changed files with 40 additions and 42 deletions

View File

@ -61,8 +61,7 @@ extension FeedListViewController {
} }
// MARK: Functions // MARK: Functions
func fetch() { func fetch() async {
Task {
isFilterEnabled = false isFilterEnabled = false
isLoading = items.isEmpty isLoading = items.isEmpty
@ -104,7 +103,6 @@ extension FeedListViewController {
isLoading = false isLoading = false
} }
}
func filter(by option: FilterOption) { func filter(by option: FilterOption) {
guard option != filter else { return } guard option != filter else { return }

View File

@ -118,7 +118,7 @@ final class FeedListViewController: UIViewController {
registerTableCells() registerTableCells()
bindViewModel() bindViewModel()
viewModel.fetch() Task { await viewModel.fetch() }
} }
} }
@ -170,7 +170,7 @@ private extension FeedListViewController {
// MARK: Actions // MARK: Actions
@objc func refresh(_ sender: AnyObject) { @objc func refresh(_ sender: AnyObject) {
self.viewModel.fetch() Task { await self.viewModel.fetch() }
} }
// MARK: Functions // MARK: Functions
@ -264,7 +264,7 @@ private extension FeedListViewController {
) )
: nil, : nil,
action: isErrorState action: isErrorState
? { self.viewModel.fetch() } ? { Task { await self.viewModel.fetch() } }
: nil : nil
) )