我与代码结合使用:
Publishers.CombineLatest($schoolId, $offset)
.filter { $0.0 > 0 && $0.1 >= 0 }
.removeDuplicates(by: { (prev, current) -> Bool in
prev.0 == current.0 && prev.1 == current.1
})
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main)
.map { APIClient.default.request(forRoute: GetMoreCommentRouter(params: ["schoolId": String($0.0), "offset": String($0.1)], method: .get), forType: [CommentModel].self)
.receive(on: DispatchQueue.main)
.replaceError(with: [])
.handleEvents(receiveSubscription: { [weak self] _ in
self?.isLoading = true
}, receiveCompletion: { [weak self] _ in
self?.isLoading = false
self?.currentText = "No comment here."
}, receiveCancel: { [ weak self] in
self?.isLoading = false
self?.currentText = "Error from server!"
}) }
.switchToLatest()
.receive(on: DispatchQueue.main)
.assign(to: \.commentList, on: self)
.store(in: &disposeStore)
当我更改偏移量时,再次调用API。我想将新数据从服务器追加到commentList。 但是我没有办法。我是联合收割机的新手。请帮助我!