Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 705 Bytes

reactive.md

File metadata and controls

32 lines (27 loc) · 705 Bytes

Reactive programming

Combine

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)