Skip to content

Instantly share code, notes, and snippets.

View yonivav's full-sized avatar

Yoni Vizel yonivav

  • TLV
View GitHub Profile
let dataSource = RxTableViewSectionedReloadDataSource<CustomSection>(
configureCell: { [weak self] _, tableView, indexPath, viewModel in
guard let cell = tableView.dequeueReusableCell(withIdentifier: CustomTableViewCell.reuseIdentifer, for: indexPath) as? CustomTableViewCell else { return UITableViewCell() }
cell.viewModel = viewModel
cell.disposeBag = self?.disposeBag // Bad idea, don't do this!
return cell
})
class MyCell: UITableViewCell {
private var disposeBag = DisposeBag()
override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag() // Destroys and disposes of old subscriptions, creates a new cell
}
}
_ = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
.subscribe(onNext: { _ in
print("Rx Resource Count: \(RxSwift.Resources.total)")
})