[英]Instance method 'flatMap' requires that 'String' conform to 'ObservableConvertibleType'
I am getting below build error for RxSwift
,我遇到了
RxSwift
的构建错误,
func testFlatMap() {
let bag = DisposeBag()
let subject = PublishSubject<String>.init()
subject.flatMap({ (value) -> String in
PublishSubject.just(value)
}).subscribe(
onNext: { value in
print(value)
}
).disposed(by: bag)
subject.on(.next("Test"))
}
Instance method 'flatMap' requires that 'String' conform to 'ObservableConvertibleType'
实例方法“flatMap”要求“String”符合“ObservableConvertibleType”
What am I missing?我错过了什么?
This is the problem:这就是问题:
subject.flatMap({ (value) -> String in
PublishSubject.just(value)
})
In the first line you are telling the compiler that the closure returns a String
but flatMap
requires the closure to return an Observable type.在第一行中,您告诉编译器闭包返回一个
String
但flatMap
要求闭包返回一个 Observable 类型。
Also, FYI: a.flatMap { .just($0) }
is effectively a no-op.另外,仅供参考:
a.flatMap { .just($0) }
实际上是无操作的。 In other words: a
≣ a.flatMap { .just($0) }
换句话说:
a
≣ a.flatMap { .just($0) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.