title: Change the Color of specific substrings in NSTextView
body: <p>I want to change the color of specific text in NSTextView. The method should check that after a keydown event. </p>
  
  <p>For example: the word void is finished and the string void changes the
  color to blue. Like a code editor.</p>
  
  <p>I searched for a long time but don't find anything.
  My Code:</p>
  
  <pre><code> NSRange range = [text rangeOfString:@"void"];
   NSString *substring = [[text substringFromIndex:NSMaxRange(range)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
   //I think, here is the mistake.
   NSAttributedString *now = [NSAttributedString initWithString:substring];
   [now setTextColor:[[NSColor blueColor]]];
  </code></pre>
  
  <p>I have read that i have to use a <code>NSAttributedString</code> but i don't know how I can get this class from a string.</p>
  
  <p>I'am quite new in cocoa programming. </p>
  
  <p>Thanks for every help!</p>