Home > Blockchain >  Combine: Casting AnyPublisher<Void, Error> to AnyPublisher<"OurType", Error>
Combine: Casting AnyPublisher<Void, Error> to AnyPublisher<"OurType", Error>

Time:03-03

I need to test the code:

func ourFunc() -> AnyPublisher<Void, Never> {
       model: OurModel = OurModel()
       Just(model).eraseToAnyPublisher()
    }

An error occurs: Cannot convert value of type OurModel to expected type Void

How we can typecast OurModel type to Void?

CodePudding user response:

I don't see any sense in it. Can you explain further?

There's no point in mapping it…

Just(model).map { _ in } .eraseToAnyPublisher()

…because it doesn't matter what the original Output was. It's all going to become ().

Just(()).eraseToAnyPublisher()
  • Related