gpt4 book ai didi

swift - 如何向 PassthroughSubject 发送错误?

转载 作者:行者123 更新时间:2023-12-03 09:23:49 26 4
gpt4 key购买 nike

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)
他们都没有编译

最佳答案

看起来 Subscribers.Completion 是一个枚举,所以这有效:

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

关于swift - 如何向 PassthroughSubject 发送错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62972404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com