Skip to content

Instantly share code, notes, and snippets.

@sobri909
Last active March 2, 2018 12:08
Show Gist options
  • Save sobri909/ceeb6ddf126164671e0abad36a6ce1a1 to your computer and use it in GitHub Desktop.
Save sobri909/ceeb6ddf126164671e0abad36a6ce1a1 to your computer and use it in GitHub Desktop.
UITextField text value observer experiments
```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