How do I do this using Objective-C and cocoa using Xcode? I am trying to insert a line into a cursor or user selection with the click of a button.
There is a -insertText method in NSTextView: it does what you want:
[myTextView insertText:@"hello world"];
The method accepts either NSString or NSAttributedString.