Skip to content

Instantly share code, notes, and snippets.

@glebus
Last active October 14, 2016 13:25
Show Gist options
  • Save glebus/4fac5d9719e03583c139454c26ee306f to your computer and use it in GitHub Desktop.
Save glebus/4fac5d9719e03583c139454c26ee306f to your computer and use it in GitHub Desktop.
class TextFieldHandler {
var handlers: [UITextField: (String) -> Void] = [:]
func bind(textField: UITextField, handler: @escaping (String) -> Void) {
textField.addTarget(self, action: #selector(textFieldChanged), for: .editingChanged)
self.handlers[textField] = handler
}
@objc func textFieldChanged(textField: UITextField) {
self.handlers[textField]?(textField.text ?? "")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment