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(.seconds(1), scheduler: MainScheduler.instance)
.subscribe(onNext: { _ in
print("Rx Resource Count: \(RxSwift.Resources.total)")
})
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
})
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 MyView: UIView {
.
.
.
init() {
self.rx
.swipeGesture(.up)
.when(.ended) // Observable<UISwipeGestureRecognizer>
.bind(to: viewModel.viewDidSwiped)
.disposed(by: bag)
viewModel.frame
.drive(onNext: { [weak self] rect in
UIView.animate(withDuration: 0.3) { [weak self] in
self?.frame = rect
}
})
.disposed(by: disposeBag)
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.data
.drive(onNext: { [weak self] someData in
self?.display(data)
})
.disposed(by: bag)
viewModel.data
.drive(onNext: { someData in
self?.display(someData)
})
.disposed(by: bag)