title: Changing font of strings separated by spaces
body: <p>I'm trying to make the words split by spaces green in a UITextField, kind of like the way it works when you compose of a new iMessage. I commented out the part of my code that's giving me a runtime error. Please let me know if you have any ideas:</p>
  
  <pre><code>func textChanged(sender : UITextField) {
  
      var myMutableString = NSMutableAttributedString()
  
      let arr = sender.text!.componentsSeparatedByString(" ")
  
      var c = 0
  
      for i in arr {
  
          /*
  
          myMutableString.addAttribute(NSForegroundColorAttributeName, value: UIColor.greenColor(), range: NSRange(location:c,length:i.characters.count))
  
          sender.attributedText = myMutableString
  
          */
  
          print(c,i.characters.count)
  
          c += i.characters.count + 1
  
      }
  
  }
  </code></pre>