RxDataSources icon indicating copy to clipboard operation
RxDataSources copied to clipboard

conform to 'RxCollectionViewDataSourceType'

Open zhangyuepeng86 opened this issue 5 years ago • 10 comments

I am a stranger to RxDataSources,when I set the datasource to UICollectionView, got the error: Instance method 'items(dataSource:)' requires that 'CollectionViewSectionedDataSource<NoticeList>' conform to 'RxCollectionViewDataSourceType'

code:

let dataSource = RxCollectionViewSectionedReloadDataSource<NoticeList> { (dataSource, collectionView, indexPath, model) -> UICollectionViewCell in
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell",
                                              for: indexPath) as! ListCollectionViewCell
            cell.titleLabel.text = model.title
            cell.numberLabel.text = String(indexPath.row)
            
            return cell
        }
...
NoticeListViewModel().data.asDriver(onErrorJustReturn: []).drive(collectionView.rx.items(dataSource: dataSource)).disposed(by:disposeBag)

zhangyuepeng86 avatar Oct 15 '20 00:10 zhangyuepeng86

me too

ghostlordstar avatar Dec 18 '20 14:12 ghostlordstar

Same here...what is even weirder is that it works in one project and fails in another project

geraldeersteling avatar Jan 14 '21 12:01 geraldeersteling

error view but successed controller

laziestlee avatar Jan 21 '21 06:01 laziestlee

same, any workaround?

syq7970 avatar Jan 22 '21 10:01 syq7970

I was having this issue, but was fixed by instead of having a DataSource of type Item you need to pass Section

typealias DataSource = RxTableViewSectionedReloadDataSource<MyCustomSection>

leyvaje avatar Jan 22 '21 14:01 leyvaje

me too :(

J-Arji avatar Apr 06 '21 11:04 J-Arji

I think your property's type or return type of function in viewModel is not Section type.

torch-ray avatar Jul 31 '21 13:07 torch-ray

still getting the same error.. i'm confused

rnjstjddn96 avatar Aug 13 '21 11:08 rnjstjddn96

same error for RxTableViewSectionedAnimatedDataSource: Instance method 'items(dataSource:)' requires that 'TableViewSectionedDataSource<LiveGenreSectionModel>' (aka 'TableViewSectionedDataSource<AnimatableSectionModel<LiveGenreSectionHeader, LiveGenreSectionItem>>') conform to 'RxTableViewDataSourceType'

WestFlow127 avatar Oct 21 '21 22:10 WestFlow127

maybe the the type of data is different from the type you set in RxTableViewSectionedReloadDataSource. here's an example:

// this is wrong because it's Observable<[String]>, not Observable<[MyCustomSection]>.
// if you write like this, you will get the error tip.
let data = Observable<[String]>.just(["first element", "second element", "third element"]) 

// Observable<[MyCustomSection]> is what it wants: array of CustomSection 
let section = MyCustomSection(header: "1", items:["first element", "second element", "third element"])
let data = Observable<[MyCustomSection]>.just([section])

let dataSource = RxTableViewSectionedReloadDataSource<MyCustomSection>(
    configureCell: { ds, tv, ip, item in
        let cell = tv.dequeueReusableCell(withIdentifier: "cell", for: ip)
        cell.textLabel?.text = "Item \(item)"
        return cell
    }
)
data.bind(to: tableView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

ratiger avatar Oct 26 '21 08:10 ratiger