NSMutableAttributedString link not working

I have some code that allows me to use a string to trigger a URL web address. However, when I click this text string it does not trigger the link, but sends the web address string to the console.


Here is some of the code in question


private let kLinkUrl = "https://www.apple.com"


private func loadText() {
        let url = Bundle.main.url(forResource: "_original_text", withExtension: "txt")
        let text = try! String(contentsOf: url!, encoding: String.Encoding.utf8)
        let attributedString = NSMutableAttributedString(string: text)

        attributedString.addLink(kLinkUrl, linkColor: kYellowColor, text: "My website")

         attributedString.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 16)
                                      range: NSRange.init(location: 0, length: attributedString.string.count))
       
        self.TextView.attributedText = attributedString

When the app launches and the text appears the text string "My website" appears in yellow but clicking on it only sends the URL address to the console.


Info.plist has "Allow Arbitrary Loads" set to Yes. It is under "App Transport Security Settings", so that is not the problem.

Also, when the textView is seleted in IB, "Selectable" is checked. I also checked "Link" but that made no difference.


My goal is to have links within the text view that are strings such as "My website" to trigger the link behind the string and take the user to the website.


Any comments or suggestions are most welcome.


Thanks!