Created
December 12, 2021 14:28
-
-
Save michzio/10a7c4af567b0b0f078f161ae71208a6 to your computer and use it in GitHub Desktop.
SwiftUI MVVM architecture - fetching cached data with refreshing
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
public func fetchWordsetCategories() -> AnyPublisher<[WordsetCategory], Error> { | |
let cachedDataPublisher = dao.fetchCategories() | |
let refreshedDataPublisher = service.getCategories(from: "pl", to: "en") | |
.flatMap { [weak self] categories in | |
self?.dao.update(categories) | |
} | |
.eraseToAnyPublisher() | |
return Publishers.MergeMany(cachedDataPublisher, refreshedDataPublisher) | |
.eraseToAnyPublisher() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment