无法将types'NSRange'(aka'_NSRange')的值转换为期望的types'Range <Index>'(又名'Range <String.CharacterView.Index>')

在检查string范围时得到此错误…

@objc func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let shouldChange = false let text = textField.text var newString = text!.stringByReplacingCharactersInRange(range, withString: string) as? NSString if newString.length > 14{ newString = newString.substringToIndex(14) } textField.text = newString.uppercaseString return shouldChange } 

而不是text!(text! as NSString)

 var newString = (text! as NSString).stringByReplacingCharactersInRange(range, withString: string) as? NSString