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

[RxDataSource] Instance method 'items(dataSource:)' requires that 'CollectionViewSectionedDataSource<T>' conform to 'RxCollectionViewDataSourceType’ #48

Closed
kimkyuchul opened this issue Jan 18, 2024 · 0 comments
Assignees
Labels

Comments

@kimkyuchul
Copy link
Owner

kimkyuchul commented Jan 18, 2024

Instance method 'items(dataSource:)' requires that 'CollectionViewSectionedDataSource' conform to 'RxCollectionViewDataSourceType’

private var dataSource = RxCollectionViewSectionedAnimatedDataSource<ArtistDataModel>(animationConfiguration: AnimationConfiguration(insertAnimation: .none, reloadAnimation: .automatic, deleteAnimation: .none)) { (datasource, collectionView, indexPath, item) in
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelectArtistCollectionViewCell", for: indexPath) as? SelectArtistCollectionViewCell else { return UICollectionViewCell() }
        
        cell.configureCell(item: item)
        return cell
  • RxCollectionViewSectionedAnimatedDataSource에 설정한 타입은 ArtistDataModel이다.
struct ArtistDataModel: SectionModelType {
  • ArtistDataModel는 SectionModelType을 채택하고 있다.
output.artistList
            .asDriver(onErrorJustReturn: [])
            .drive(artistCollectionView.rx.items(dataSource: dataSource))
            .disposed(by: disposeBag)

// *Instance method 'items(dataSource:)' requires that 'CollectionViewSectionedDataSource<ArtistDataModel>' conform to 'RxCollectionViewDataSourceType’*
  • 그러나 서버에서 받아올 당시 ArtistDataModel로 변환해주지 않아서 다음과 같은 오류가 발생 한 것이다.
  • Instance method 'items(dataSource:)' requires that 'CollectionViewSectionedDataSource' conform to 'RxCollectionViewDataSourceType’
output.artistList
            .map { [ArtistDataModel(title: "", items: $0)] }
            .asDriver(onErrorJustReturn: [ArtistDataModel(title: "", items: [])])
            .drive(artistCollectionView.rx.items(dataSource: dataSource))
            .disposed(by: disposeBag)
  • 다음과 같이 SectionModelType을 채택하고 있던 ArtistDataModel로 변환 바인딩시켜줘야 한다.

RxSwiftCommunity/RxDataSources#376

@kimkyuchul kimkyuchul self-assigned this Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant