UITextViewDelegate方法在Swift 3和Xcode 8.0中给出了“使用未声明的类型URL”的错误

问题描述:

当我在我的swift类中实现func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Boolfunc textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool方法时,它会给出错误和警告,如下所示。UITextViewDelegate方法在Swift 3和Xcode 8.0中给出了“使用未声明的类型URL”的错误

错误:Use of undeclared type 'URL'

警告:Instance method 'textView(_:shouldInteractWith:in:)' nearly matches optional requirement 'textView(_:shouldInteractWith:in:)' of protocol 'UITextViewDelegate'

如果我更改类名NSURL而不是URL,它正确编译,但报警从未熄灭。

而且同时用URL在我的TextView互动

由于上述方法不叫!

尝试改变方法报头是这样的:(url需要在小写形式参数)

func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange) -> Bool 

这绝对是夫特/ Xcode中的一个错误。正式参数URL是阴影类型URL

+0

是的,你是对的,错误在UITextViewDelegate方法中。感谢您的解决! – Natarajan