'"NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds"

I'm new to swift! I would like to add a link to a text inside my View Controller, I found this code below.

When I run the App crash and is returning this error message:

"NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds"

I appreciate any help, thanks.

class ViewController: UIViewController, UITextViewDelegate {
    @IBOutlet var textView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let attributedString = NSMutableAttributedString(string: "Link")
        attributedString.addAttribute(.link, value: "https://www.apple.com", range: NSRange(location: 19, length: 55))
        
        textView.attributedText = attributedString
    }
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        UIApplication.shared.open(URL)
        return false
    }
    
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source