That's a UITextFieldDelegate method, so you need to make your View Controller conform to it. The example with English alphabet:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if !["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"].contains(string.lowercased()) {
return false
}
return true
}
Remember to set your textfield's delegate to self (your ViewController):
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
engTextField.delegate = self
}
UPD: May be it's better to use !Array("qwertyuiopasdfghjklzxcvbnm").contains(string.lowercased())