title: NSRange crashing app
body: <p>I have an issue with NSRange that is causing my app to crash when textview is empty.  I am using a custom keyboard that has a backspace button on it and it calls this code here...</p>
  
  <pre><code>if ([self.myChart isFirstResponder]) {
      NSRange currentRange = myChart.selectedRange;
      if (currentRange.length == 0) {
          currentRange.location--;
          currentRange.length++;
      }
      myChart.text = [myChart.text stringByReplacingCharactersInRange:currentRange withString:[NSString string]];
      currentRange.length = 0;
      myChart.selectedRange = currentRange;
  
      NSLog(@"%d", NSNotFound);
  }
  </code></pre>
  
  <p>If I have text in the textview this works perfectly for removing one character at a time however when I get to the beginning of the textview and there are no more characters, I get the exception and crash...</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'
  </code></pre>
  
  <hr>
  
  <p>My goal is to have the backspace function stop.  I understand why it is crashing but I don't know how to resolve it.  I have tried evaluating it against NSNotFound without luck.</p>
  
  <p>Any ideas would be much appreciated!</p>