I have a UITextView implemented as:

```
let textView = UITextView()
textView.isEditable = false
textView.dataDetectorTypes = .link

```

I know that setting the data detector type to link means that the text view will automatically find links, highlight them, and hyperlink them (make them tappable).

What I am trying to figure out is how to know whether or not the UITextView found at least one URL, and do something with that first URL programmatically. I've considered using regex to try to find common URL formats, but I'd like consistency with the way Apple does the detection.

Is there a way to extract the URL from attributedText, or is there an even simpler way to do it?

I think it could be done with something like this:

```
textView.attributedText.attribute(.link, at: 0, effectiveRange: 0..textView.text.count)

```