Oscar Cooke-Abbott
Oscar Cooke-Abbott

Reputation: 503

Use of undeclared type 'URL' in textView(_:shouldInteractWith:in:)

I am currently working on a simple app that retrieves some text and sets some UITextView's to the text with link autodetection enabled, and whilst attempting to allow the user to tap on the link, I have run into this issue whereby whilst attempting to implement the UITextView delegate to enable link redirection, the parser gives the error of: Use of undeclared type 'url'

If I try and use the newer version of textView(_:shouldInteractWith:in:interaction:), the parser also gives the same: Use of undeclared type error for the UITextItemInteraction

func textView(textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange) -> Bool {
    return true
}

Upvotes: 0

Views: 1202

Answers (2)

Matthew Seaman
Matthew Seaman

Reputation: 8092

Check the documentation on that method. There is actually a fourth argument of type UITextItemInteraction. It is most likely declared optional and when you don't list it in your definition it just assumes you don't care about it, but it's still there. And it turns out UITextItemInteraction is only available in iOS 10 and later. If Xcode thinks 9.3 is the latest, your Xcode is out of date. You should update to Xcode 8. You can still target iOS 9 if you really want, but you'll need to mark that method as only available for iOS 10, something the Xcode 8 compiler errors should walk you through.

Upvotes: 1

Yogesh MV
Yogesh MV

Reputation: 1051

Check the method definition given below

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool { return true }

Upvotes: 0

Related Questions