Skip to content

Instantly share code, notes, and snippets.

View yonivav's full-sized avatar

Yoni Vizel yonivav

  • TLV
View GitHub Profile
_ = Observable<Int>.interval(1, scheduler: MainScheduler.instance)
.subscribe(onNext: { _ in
print("Rx Resource count \(RxSwift.Resources.total)")
})
@yonivav
yonivav / badBind.swift
Created February 20, 2019 15:22
Where is the dispose action? Where?!?!
viewModel
.btnTitle
.drive(btn.rx.title(for: .normal))
private let dataSource = RxTableViewSectionedReloadDataSource<TableViewSection>(
configureCell: { [weak self] _, table, indexPath, viewModel in
guard let cell = table.dequeueReusableCell(withIdentifier: TableViewCell.reuseIdentifier, for: indexPath) as? TableViewCell else {
return UITableViewCell()
}
cell.viewModel = viewModel
cell.disposeBag = self.disposeBag // Bad Idea, don't do that!
return cell
})
viewModel.data
.drive(onNext: { [weak self] someData in
self?.display(data)
})
.disposed(by: bag)
service
.flatMap { [weak self] text -> Observable<Void> in
guard let self = self else { return .empty() }
.
.
.
return self.network
.request(url: url)
.do(onNext: { response in
self.status.value = .success(response)
viewModel.frame
.drive(onNext: { [weak self] rect in
UIView.animate(withDuration: 0.3) { [weak self] in
self?.frame = rect
}
})
.disposed(by: disposeBag)
class MyView: UIView {
.
.
.
init() {
self.rx
.swipeGesture(.up)
.when(.ended)
.map { $0.view?.frame }
.bind(to: viewModel.viewDidSwiped)
class MyView: UIView {
.
.
.
init() {
self.rx
.swipeGesture(.up)
.when(.ended)
.subscribe { [weak self] swipeGestureRecognizer in
guard let self = self else { return }
class MyCell: UITableViewCell {
private var disposeBag = DisposeBag()
override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag() // Destroys and disposes of old subscriptions, creates a new cell
}
}
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
})