无法将“(AnyPublisher<DemoObject,Never>,APIError)”类型的返回表达式转换为“AnyPublisher<DemoObject,APIError>”类型

func testData()->AnyPublisher<DemoObject, APIError> {

    var data = DummyData().decodeClaimDetails()!
    
    return (Just(data).eraseToAnyPublisher(),
            APIError.httpError(200))
    
}

我收到了这个错误。无法将“(AnyPublisher<DemoObject, Never>, APIError)”类型的返回表达式转换为“AnyPublisher<DemoObject, APIError>”类型

如何返回 AnyPublisher<DemoObject, APIError> 类型?

回答

你要

func testData()->AnyPublisher<DemoObject, APIError> {
    let d: DemoObject = // ...
    return Just<DemoObject>(d)
        .setFailureType(to: APIError,self) // <--
        .eraseToAnyPublisher()
}


以上是无法将“(AnyPublisher&lt;DemoObject,Never&gt;,APIError)”类型的返回表达式转换为“AnyPublisher&lt;DemoObject,APIError&gt;”类型的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>