leak
alouanemed opened this issue · comments
Mohamed Alouane commented
I have a table view cell with a collection view. both bonded through rxdatasource, I am getting the leak using instruments when the view is loaded. Any thoughts on what could be the reason for this? Thanks.
the leak
HomeViewcontroller
let dataSource = RxTableViewSectionedReloadDataSource<HomeSection>(configureCell: { [weak self] dataSource, tableView, indexPath, item in
guard let self = self else { return UITableViewCell() }
switch item {
....
case .homeTrendingItem(let viewModel):
let cell = (tableView.dequeueReusableCell(withIdentifier: trendingIdentifier, for: indexPath) as? ModelProductsCell)!
cell.delegate = self
cell.bind(to: viewModel)
return cell
}
}, titleForHeaderInSection: { dataSource, index in
let section = dataSource[index]
return section.title
})
output.items
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: rx.disposeBag)
ModelProductsCell
func bind(to viewModel: ModelProductsViewModel) {
let input = ModelProductsViewModel.Input()
let output = viewModel.transform(input: input)
output.items
.bind(to: collectionView.rx.items(cellIdentifier: mainReuseIdentifier, cellType: ProductItemCell.self)) { collectionView, viewModel, cell in
cell.bind(to: viewModel)
}.disposed(by: cellDisposeBag)
collectionView.rx.modelSelected(ProductCellViewModel.self)
.bind {[weak self] vm in
self?.delegate?.didTapOnItem(p: vm.product)
}.disposed(by: cellDisposeBag)
viewModel.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag)
viewModel.loading.asDriver().drive(onNext: { [weak self] (isLoading) in
isLoading ? self?.activityIndicator.startAnimating() : self?.activityIndicator.stopAnimating()
}).disposed(by: cellDisposeBag)
}