我有这段代码,但我不确定。
NewsAPI.fetchNews(page: loadedPage.value + 1)
.observeOn(MainScheduler.asyncInstance)
.bind(onNext: { [weak self](news) in
guard let strongSelf = self else { return }
strongSelf.news.value = strongSelf.news.value + news
strongSelf.loadedPage.value = strongSelf.loadedPage.value + 1
})
.disposed(by: disposeBag)
答案 0 :(得分:1)
你的例子应该可行,但这里有一些评论:
onTick
或NewsAPI.fetchNews(page: loadedPage.value + 1)
方法处理subscribe
的结果(适用于drive
/ Observable
类型); Driver
(和其他人)应替换为strongSelf.loadedPage.value = strongSelf.loadedPage.value + 1
。结果:
strongSelf.loadedPage.value += 1