我有这样的代码在Objective-C:stringByReplacingCharactersInRange如何在swift中工作?
[textField.text stringByReplacingCharactersInRange:range withString:string];
尝试转换为迅速,像这样:
textField.text.stringByReplacingCharactersInRange(range, withString: string)
但是编译器说,Int is not identical to 'String.index'
我应该如何修改体现在哪里?
我同时使用的Objective-C/SWIFT表达的UITextFieldDelegate方法:
func textField(textField: UITextField!,
shouldChangeCharactersInRange range: NSRange,
replacementString string: String!) -> Bool {
你是如何定义'range',在这两种情况下? – Undo
两者都有NSRange类型 –
我得到了一个不同的错误消息,有关的范围,而不是字符串,就像其他线程 –