title: How does stringByReplacingCharactersInRange work in swift?
body: <p>I have this code in objective-c:</p>
  
  <pre><code>[textField.text stringByReplacingCharactersInRange:range withString:string];
  </code></pre>
  
  <p>try to convert to swift, like so:</p>
  
  <pre><code>textField.text.stringByReplacingCharactersInRange(range, withString: string)
  </code></pre>
  
  <p>but compiler says, <code>Int is not identical to 'String.index'</code></p>
  
  <p>How should I modify expression?</p>
  
  <p>I am using both objective-c / swift expressions in UITextFieldDelegate method:</p>
  
  <pre><code>func textField(textField: UITextField!,
      shouldChangeCharactersInRange range: NSRange,
      replacementString string: String!) -&gt; Bool {
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/z7z7B.png" alt="enter image description here"></p>