Created
December 12, 2021 14:49
-
-
Save michzio/17851ff3cb40025a5c603e6ed0b408d3 to your computer and use it in GitHub Desktop.
SwiftUI MVVM architecture - ViewModel simplified
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
@Published var categories: [WorsetCategory] = [] | |
@Published var error: Error? | |
@Published var isLoading: Bool = false | |
func fetchWordsetCategories() { | |
guard !isLoading else { return } | |
repo.fetchWordsetCategories() | |
.sink(receiveCompletion: { completion in | |
switch completion { | |
case .failure(let error): | |
self?.error = error | |
case .finished: | |
break | |
} | |
self?.isLoading = false | |
}) { [weak self] categories in | |
self?.categories = categories | |
} | |
.store(in: &disposables) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment