【问题标题】:How do I send an error to a PassthroughSubject?如何向 PassthroughSubject 发送错误?
【发布时间】:2020-07-18 18:39:57
【问题描述】:
let myPassthrough = PassthroughSubject<String, Error>()

我知道我可以使用send 向传递主题发送值:

myPassthrough.send("abc")

如何发送失败消息?


我试过了:

myPassthrough.send(Fail(error: error))
myPassthrough.send(completion: Fail(error: error))
myPassthrough.send(completion: Just(error))
myPassthrough.send(completion: error)

它们都不编译

【问题讨论】:

    标签: swift combine


    【解决方案1】:

    看起来 Subscribers.Completion 是一个枚举,所以这行得通:

    myPassthrough.send(completion: .failure(error))
    

    【讨论】:

    • 谢谢。那行得通。
    猜你喜欢
    • 2020-11-03
    • 2018-08-21
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 2018-09-08
    • 2017-07-26
    • 1970-01-01
    相关资源
    最近更新 更多