Pick the fix
Why does func searchResults() -> AnyPublisher<[Item], Never> end with .eraseToAnyPublisher()?
Hint 1 of 1
Look at the type a chain of operators produces.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A To hide the long nested operator type so callers depend only on Output and Failure
Correct. The implementation can change without breaking callers.
Why not the others?
- B To make the publisher run on the main thread. Use receive(on:) for that.
- C To make the pipeline faster. Erasure adds a small cost; it doesn't speed anything up.
- D To keep the subscription alive. That is what AnyCancellable does.