Last active
March 2, 2018 12:08
-
-
Save sobri909/ceeb6ddf126164671e0abad36a6ce1a1 to your computer and use it in GitHub Desktop.
UITextField text value observer experiments
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
```swift | |
// SwiftNotes, observing via NotificationCenter | |
when(field, does: .UITextFieldTextDidChange) { [weak self] _ in | |
log("UITextFieldTextDidChange (newValue: \(field.text)))") | |
self?.textFieldChanged() | |
} | |
// MGObserver, observing via old school objc KVO methods | |
field.onChangeOf("text") { [weak self] in | |
log("field.onChangeOf(text) (newValue: \(field.text)))") | |
self?.textFieldChanged() | |
} | |
// Swift 4(?)'s new observer method? can't find it in the docs anywhere! | |
textObserver = field.observe(\.text) { [weak self] field, change in | |
log("field.observe(text) (newValue: \(field.text)))") | |
self?.textFieldChanged() | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment