I know there are a lot of questions about this, I looked at all of them but it doesn't fix my problem. I also commented on one of them but the question doesn't seem to be active anymore so I don't expect an answer there.
I'm trying to implement RxDataSources. See my code below:
struct ActiveOrdersSection: Equatable {
static func == (lhs: ActiveOrdersSection, rhs: ActiveOrdersSection) -> Bool {
return true
}
var header: String
var orders: [Order]
}
extension ActiveOrdersSection: SectionModelType {
typealias Item = Order
var items: [Item] {
set {
orders = items
}
get {
return orders
}
}
init(original: ActiveOrdersSection, items: [Order]) {
self = original
self.items = items
}
}
And the ViewController:
class MainViewController: UITableViewDelegate, UITableViewDataSource {
var db: DisposeBag?
var dataSource: RxTableViewSectionedReloadDataSource<ActiveOrdersSection>?
private func setupOrderRx(_ shopId: Int64) {
let dataSource = RxTableViewSectionedReloadDataSource<ActiveOrdersSection>(
configureCell: { ds, tv, ip, item in
let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: ip) as! UITableViewCell
cell.textLabel?.text = "Item \(item.id)"
return cell
},
titleForHeaderInSection: { ds, ip in
return ds.sectionModels[ip].header
}
)
self.dataSource = dataSource
db = DisposeBag()
let ors = OrderRxService.listAsShop(shopId, status: .active)
.map { Observable.just($0.items) } // Convert from Observable<CollectionResponse<Order>> to Observable<Order>
.observeOn(MainScheduler.instance)
.bind(to: self.rxTableView.rx.items(dataSource: dataSource))
}
}
I get Generic parameter 'Self' could not be inferred
on .bind(to: self.rxTableView.rx.items(dataSource: dataSource))
. I looked at the RxDataSources examples and seem to have it the same now, but I can't seem to fix this error.
Any ideas?
The Rx stream you bind to your RxTableViewSectionedReloadDataSource
has to be of type Observable<[ActiveOrdersSection]>
. I don't know exactly what your types are in this example because the code you provided is not enough but
I think that by using .map { Observable.just($0.items) }
the result stream will be of type Observable<Observable<[Order]>>
.
Try to change it to:
.map { [ActiveOrdersSection(header: "Your Header", orders: 0.items)] }