Getting this error when checking the range for string characters...
@objc func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, re
Swift 4
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
if let oldString = textField.text {
let newString = oldString.replacingCharacters(in: Range(range, in: oldString)!,
with: string)
// ...
}
// ...
}
Instead of text!
say (text! as NSString)
.
var newString = (text! as NSString).stringByReplacingCharactersInRange(range, withString: string) as? NSString