Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created October 23, 2017 04:59
Show Gist options
  • Save azamsharp/5b999b676d12fa785e176df6c137fcb8 to your computer and use it in GitHub Desktop.
Save azamsharp/5b999b676d12fa785e176df6c137fcb8 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
class BindingTextField : UITextField {
var textChanged :(String) -> () = { _ in }
func bind(callback :@escaping (String) -> ()) {
self.textChanged = callback
self.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
}
@objc func textFieldDidChange(_ textField :UITextField) {
self.textChanged(textField.text!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment