Created
April 25, 2016 19:16
-
-
Save jollyjoester/5512fb389104742b5ac80d125881e125 to your computer and use it in GitHub Desktop.
RxSwift触ってみた ref: http://qiita.com/jollyjoester/items/c4013c60acd453ea7248
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
$ pod install | |
... | |
Installing RxBlocking (2.4) | |
Installing RxCocoa (2.4) | |
Installing RxSwift (2.4) | |
Installing RxTests (2.4) | |
... |
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
Xcode | |
Version 7.3 (7D175) | |
pod --version | |
0.39.0 |
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
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 |
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
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 | |
} | |
) | |
} | |
} |
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 | |
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