I am working on a UITextView
that is populated by a NSAttributedString
.
I use the following code to extract the URL out of the attributed string:
if let attribute = self.textStorage.attribute(NSAttributedString.Key.link, at: characterIndex, effectiveRange: nil){
let url = URL(string: (attribute as AnyObject).debugDescription ?? "");
print("URL: \(url.absoluteString)");
}
It does not seem like an efficient way to get the URL
, because I am converting the attribute to its debug description, then using that to initialize a new URL
.
Is there a more "official" way to get the URL
from the attribute?