Last active
April 11, 2016 15:10
-
-
Save YusukeHosonuma/e2f0718968a0f4e13c0148bf8cb22afe to your computer and use it in GitHub Desktop.
RxSwift - Nofication sample
This file contains hidden or 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 | |
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