Guest User

Untitled

a guest
Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import Foundation
  2. import UIKit
  3.  
  4. class BindingTextField : UITextField {
  5.  
  6. var textChanged :(String) -> () = { _ in }
  7.  
  8. func bind(callback :@escaping (String) -> ()) {
  9.  
  10. self.textChanged = callback
  11. self.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
  12. }
  13.  
  14. @objc func textFieldDidChange(_ textField :UITextField) {
  15.  
  16. self.textChanged(textField.text!)
  17. }
  18.  
  19. }
Add Comment
Please, Sign In to add comment