【发布时间】:2016-05-06 20:15:03
【问题描述】:
我一直在开发一个搜索控制器,当用户在搜索字段中输入时,它使用 RxSwift 更新 DataSource,如下所述:http://www.thedroidsonroids.com/blog/ios/rxswift-examples-3-networking/
这是我的视图模型:
struct SearchControllerViewModel {
let provider: RxMoyaProvider<ThreadifyEndpoint>
let startsWith: Observable<String>
func startSearching() -> Observable<[SearchedNodeViewModel]> {
return startsWith
.observeOn(MainScheduler.instance)
.flatMapLatest { query -> Observable<[SearchedNodeViewModel]?> in
return self.findNodes(query)
}.replaceNilWith([])
}
internal func findNodes(startsWith: String) -> Observable<[SearchedNodeViewModel]?> {
return self.provider
.request(ThreadifyEndpoint.SearchForNodes(startsWith: startsWith))
.mapArrayOptional(SearchedNodeViewModel.self)
}
}
现在我希望不仅在用户输入时加载新数据,而且在 sh 向下滚动时加载。 我正在考虑使用 combineLatest 来观察 rx_text 和 rx_offset 但由于编译错误,我无法将 Observable 传递给 combineLatest。
【问题讨论】:
-
什么是编译错误? combineLatest 需要多个 Observable,所以这很奇怪。
-
@solidcell 无法使用类型为 (Observable
, Observable ) 的参数列表调用“combineLatest” -
我已经在下面回答了。此外,如果您使用
swift标签标记您的 Swift 问题,您的问题(和答案)将获得语法高亮显示。