Skip to content

Instantly share code, notes, and snippets.

@YusukeHosonuma
Last active April 11, 2016 15:10
Show Gist options
  • Save YusukeHosonuma/e2f0718968a0f4e13c0148bf8cb22afe to your computer and use it in GitHub Desktop.
Save YusukeHosonuma/e2f0718968a0f4e13c0148bf8cb22afe to your computer and use it in GitHub Desktop.
RxSwift - Nofication sample
import UIKit
import RxSwift
import RxCocoa
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var countLabel: UILabel!
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
// Update char count label, when textview did change and first.
NSNotificationCenter.defaultCenter()
.rx_notification(UITextViewTextDidChangeNotification)
.startWith(NSNotification(name: "startup", object: nil))
.subscribeNext { [unowned self] _ in
let count: Int = self.textView.text?.characters.count ?? 0
self.countLabel.text = "count: \(count)"
}
.addDisposableTo(disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment