Hi everyone,
I have been playing around with the shouldChangeTextIn method, trying to create some code that will exclude certain characters from the textView, and noticed that the first character typed into the textView doesn't register in the console output. If I type 'a' it returns that is it not a letter on the first input, but does acknowledge it as a letter from then on. Likewise, if I switch to numbers, the initial input isn't acknowledged as not being a letter. I'm guessing that the initial input doesn't actually register until the second character is typed in, so everything is a step out from then on. Can anyone point me to some documentation that will enlighten me on this? Should the first output just be ignored, tossed to the trash so to speak, while everything from then on is treated as having a value?
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
let currentText = textView.text ?? ""
let singleLetter = currentText.last ?? " "
if singleLetter.isLetter == true {
print("Is letter")
return true
}else {
print("Is not letter")
return true
}
}
P.S. Apologies if this is posted in the wrong section. I think I might have it right, but am not entirely sure.