Skip to content

Instantly share code, notes, and snippets.

@DianQK
Created May 25, 2016 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DianQK/c2ca65507e7d790cb2cb1835dfcbe570 to your computer and use it in GitHub Desktop.
Save DianQK/c2ca65507e7d790cb2cb1835dfcbe570 to your computer and use it in GitHub Desktop.
StopWhenTap
import UIKit
import RxSwift
import RxCocoa
import NSObject_Rx
class ViewController: UIViewController {
@IBOutlet var stop: UIButton!
let timer = Observable<Int>.interval(1, scheduler: MainScheduler.instance)
override func viewDidLoad() {
super.viewDidLoad()
timer
.takeUntil(stop.rx_tap)
.subscribe { event in
switch event {
case .Next(let value):
print(value)
case .Error(let error):
print(error)
case .Completed:
print("Completed")
}
}
.addDisposableTo(rx_disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment