NSMutableAttributedString.addAttribute
func addAttribute (_ name: NSAttributedStringKey, value: Any, range: NSRange)
NSAttributedStringKey is defined as a struct
with static members; one of them is foregroundColor.
override func viewDidLayout() {
print (#function)
let text = "Hoot, Hoot!"
var fancyText = NSMutableAttributedString (string: text)
fancyText.addAttribute (NSAttributedStringKey.foregroundColor, value:NSColor.red, range:NSRange (location:0, length:fancyText.length))
outletTextView.insertText (fancyText, replacementRange: NSRange (location:0, length:0))
}