I have a textfield with maximum character range 16, After every 4 characters, I want to add minus character or space and then writing The rest of the characters
To do it "on the fly", I connected Editing changed to this IBAction ; needs also to care for backspace
@IBAction func editingTestField(_ sender: UITextField) {
if sender.text!.count > 0 && sender.text!.count % 5 == 0 && sender.text!.last! != "-" {
sender.text!.insert("-", at:sender.text!.index(sender.text!.startIndex, offsetBy: sender.text!.count-1) )
}
}