Apexy supports Combine framework
How to use by example BookService
(see Example project).
final class BookService {
...
func fetchBooks() -> AnyPublisher<[Book], Error> {
let endpoint = BookListEndpoint()
return apiClient.request(endpoint)
}
...
}
bookService.fetchBooks().sink(receiveCompletion: { [weak self] completion in
self?.activityView.isHidden = true
switch completion {
case .finished:
break
case .failure(let error):
self?.resultLabel.text = error.localizedDescription
}
}, receiveValue: { [weak self] books in
self?.show(books: books)
}).store(in: &bag)