【发布时间】:2020-08-07 18:23:48
【问题描述】:
我有一个像下面这样的 Swift 发布者
let item = PassthrogutSubject<String, Never>()
收到字符串后我要发起网络请求
为此,我使用flatMap
我的网络请求签名如下:
func loadDetails(_ code: String) -> AnyPublisher<CustomType, ErrorAlert>
我怎样才能做到以下几点:
$item
.filter { !$0.isEmpty }
.flatMap { [unowned self] (string) in
self.viewModel.loadDetails(string) }
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in
...
}) { ... }
.store(in: &subscriptions)
错误:
Instance method 'flatMap(maxPublishers:_:)' requires the types 'Published<Value>.Publisher.Failure' (aka 'Never') and 'Alert' be equivalent
【问题讨论】:
标签: ios swift networking functional-programming combine