Last active
May 4, 2020 06:21
-
-
Save Dimillian/14e82653afdc0189e98b0ed9b4562322 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 class Items: ObservableObject { | |
@Published public var categories: [Category: [Item]] = [:] | |
init() { | |
for category in Category.allCases { | |
_ = NookPlazaAPIService | |
.fetch(endpoint: category) | |
.replaceError(with: ItemResponse(total: 0, results: [])) | |
.eraseToAnyPublisher() | |
.map{ $0.results } | |
.receive(on: DispatchQueue.main) | |
.sink(receiveValue: { [weak self] items in self?.categories[category] = items }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment