title: NSAttributedString change color at end of string
body: <p>This must be an easy thing to do, but I cannot figure it out.</p>
  
  <p>I have a NSMutableAttributedString that has, for example, "This is a test" in it.  I want to color the word "test" blue, which I do with this:</p>
  
  <pre><code>NSMutableAttributedString *coloredText = [[NSMutableAttributedString alloc] initWithString:@"This is a test"];
  
  [coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(10,4)];
  </code></pre>
  
  <p>That works just fine.  But now I want to set the text color back to black for anything typed after "test".</p>
  
  <p>If I do:</p>
  
  <pre><code>[coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(coloredText.string.length, 1)];
  </code></pre>
  
  <p>I get an objectAtIndex:effectiveRange: out of bounds error.  Assumedly because the range extends beyond the length of the string.</p>
  
  <p>If I do:</p>
  
  <pre><code>[coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(coloredText.string.length, 0)];
  </code></pre>
  
  <p>The error goes away but typing after the word "test" remains blue.</p>
  
  <p>How do I set the current color at the insertion point when it is at the end of the string??</p>
  
  <p>Cheers for any input.</p>