Skip to content

Instantly share code, notes, and snippets.

@jollyjoester
Created April 25, 2016 19:16
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 jollyjoester/5512fb389104742b5ac80d125881e125 to your computer and use it in GitHub Desktop.
Save jollyjoester/5512fb389104742b5ac80d125881e125 to your computer and use it in GitHub Desktop.
$ pod install
...
Installing RxBlocking (2.4)
Installing RxCocoa (2.4)
Installing RxSwift (2.4)
Installing RxTests (2.4)
...
Xcode
Version 7.3 (7D175)
pod --version
0.39.0
use_frameworks!
target 'RxSwiftSample' do
pod 'RxSwift', '~> 2.0'
pod 'RxCocoa', '~> 2.0'
end
# RxTests and RxBlocking have most sense in the context of unit/integration tests
target 'RxSwiftSampleTest' do
pod 'RxBlocking', '~> 2.0'
pod 'RxTests', '~> 2.0'
end
extension UITextField {
/**
Reactive wrapper for `text` property.
*/
public var rx_text: ControlProperty<String> {
return UIControl.rx_value(
self,
getter: { textField in
textField.text ?? ""
}, setter: { textField, value in
textField.text = value
}
)
}
}
import UIKit
class ViewController: UIViewController {
// for existing impl
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var textField2: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// for existing impl
label2.text = "「」"
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(UITextInputDelegate.textDidChange(_:)), name: UITextFieldTextDidChangeNotification, object: self.textField2)
}
// ...
func textDidChange(notification: NSNotification) {
if let text = textField2.text {
label2.text = "\(text)"
}
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment