Is there something like textFieldDidChange available in Xcode 12 that will run on iOS versions earlier than 13?
I am using this function to read the contents of a UITextField whenever it changes:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { guard CharacterSet(charactersIn: "0123456789").isSuperset(of: CharacterSet(charactersIn: string)) else { return false } let s: String = textField.text ?? "" print("s = \(s)") return true } but the printed output is always one character behind.
For example: When I type in 1 the printed output is s = ". Adding a 2 (the textfield now displays 12) prints s = 1. After a 3 (textfield now contains 123), s = 12. And so on. Always one character behind.
Why is this? (I'm guessing because the character does not become part of the textfield.text until the function returns true.)
This gets the contents:
func textFieldDidChangeSelection(_ textField: UITextField) { let s: String = textField.text ?? "" print("s = \(s)") } but it only works with iOS 13.x.
How do I get the contents of a UITextfield whenever it changes for any iOS version?
textDidChange. Take a look at UIKitPlus lib it is much easier to use than pure UIKit