As noted in a comment on the Randall website , in 10.6 or later there is a simple way:
[self.textView checkTextInDocument:nil]
Depending on how the view is configured, this can do more than just add links - for example, it can add smart quotes. You can use setEnabledTextCheckingTypes: to indicate what you want to check. In my case, I want smart quotes to be included during typing, but I don't want them to be added when I change text programmatically. So I can use something like this:
NSTextCheckingTypes oldTypes = self.textView.enabledTextCheckingTypes; [self.textView setEnabledTextCheckingTypes:NSTextCheckingTypeLink]; [self.textView checkTextInDocument:nil]; [self.textView setEnabledTextCheckingTypes:oldTypes];
This will revert the field to its previous behavior after adding links.
robotspacer
source share