Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode crashes while adding RxDataSource to UICollectionView

Hey I'm trying to get an UICollectionView, hosted by an UICollectionViewController working with RxCocoa and RxDataSources.

Everything works fine when I use an UIViewController, with an embedded UICollectionView.

But when I try to connect via the same logic:

        self.vm.sections
        .bind(to: self.collectionView!.rx.items(dataSource: self.vm.data))
        .disposed(by: self.bag)

with an UICollectionView inside an UICollectionViewController, Xcode crashes completely.

Is there something I'm missing about RxDataSources, that you cannot use them with UICollectionViewController?

like image 698
vander2675 Avatar asked Mar 15 '26 20:03

vander2675


2 Answers

Though I have no idea about why Xcode crashes, it seems to be caused by RxCocoa's assertion checking.

The data source of UICollectionViewController's collectionView is set by default. How about setting it to nil before binding with observable?

self.collectionView!.dataSource = nil
self.vm.sections
.bind(to: self.collectionView!.rx.items(dataSource: self.vm.data))
.disposed(by: self.bag)
like image 146
Hiron Avatar answered Mar 17 '26 08:03

Hiron


If you inherit from UITableViewController you must call tableView.datasource = nil anytime you are doing a whole table reload or refresh action

like image 25
Cjay Avatar answered Mar 17 '26 08:03

Cjay