I would like to count the character when user keep typing in UITextField with swift.
Image of Field and Label:
A very elegant and neat solution exists using UITextFieldDelegate. My solution uses the concept of selectors. In a selector you tell your compiler what function/action to perform when a particular event happens. In this case - typing in textfield. Make sure that you have set the textField delegate in storyboard.
override func viewDidLoad() {
super.viewDidLoad()
yourTextField.addTarget(self, action: #selector(YourViewController.textFieldDidChange(_:)), for: UIControlEvents.EditingChanged)
}
@objc func textFieldDidChange(textField : UITextField){
label.text = yourTextField.text?.count
}