title: How shouldChangeCharactersInRange works in Swift?
body: <p>I'm using <em>shouldChangeCharactersInRange</em> as a way of using on-the-fly type search.</p>
  
  <p>However I'm having a problem, <em>shouldChangeCharactersInRange</em> gets called before the text field actually updates:</p>
  
  <p>In Objective C, I solved this using using below:</p>
  
  <pre><code>-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
      NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
  
      return YES;
  }
  </code></pre>
  
  <p>However, I've tried writing this in Swift:</p>
  
  <pre><code>func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -&gt; Bool {
      let txtAfterUpdate:NSString = self.projectSearchTxtFld.text as NSString
      txtAfterUpdate.stringByReplacingCharactersInRange(range, withString: string)
  
      self.callMyMethod(txtAfterUpdate)
      return true
  }
  </code></pre>
  
  <p>The method still gets called before I get a value?</p>