Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conform to 'RxCollectionViewDataSourceType' #376

Open
zhangyuepeng86 opened this issue Oct 15, 2020 · 10 comments
Open

conform to 'RxCollectionViewDataSourceType' #376

zhangyuepeng86 opened this issue Oct 15, 2020 · 10 comments

Comments

@zhangyuepeng86
Copy link

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)
@ghostlordstar
Copy link

me too

@geraldeersteling
Copy link

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

@laziestlee
Copy link

error view but successed controller

@syq7970
Copy link

syq7970 commented Jan 22, 2021

same, any workaround?

@leyvaje
Copy link

leyvaje commented Jan 22, 2021

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>

@J-Arji
Copy link

J-Arji commented Apr 6, 2021

me too :(

@torch-ray
Copy link

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

@rnjstjddn96
Copy link

still getting the same error.. i'm confused

@WestFlow127
Copy link

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

@ratiger
Copy link

ratiger commented Oct 26, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests