Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Last active May 4, 2020 06:21
Show Gist options
  • Save Dimillian/14e82653afdc0189e98b0ed9b4562322 to your computer and use it in GitHub Desktop.
Save Dimillian/14e82653afdc0189e98b0ed9b4562322 to your computer and use it in GitHub Desktop.
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