Created
May 25, 2016 07:21
-
-
Save DianQK/c2ca65507e7d790cb2cb1835dfcbe570 to your computer and use it in GitHub Desktop.
StopWhenTap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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