How to map error in Combine
Issue #506
When a function expects AnyPublisher<[Book], Error>
but in mock, we have Just
1 | func getBooks() -> AnyPublisher<[Book], Error> { |
There will be a mismatch, hence compile error
Cannot convert return expression of type ‘AnyPublisher<[Book], Just
The reason is because Just produces Never
, not Error
. The workaround is to introduce Error
1 | enum AppError: Error { |
1 | func getBooks() -> AnyPublisher<[Book], Error> { |
Updated at 2020-11-07 20:30:01