【问题标题】:UITextViewDelegate method gives "Use of undeclared type URL" error in Swift 3 and Xcode 8.0UITextViewDelegate 方法在 Swift 3 和 Xcode 8.0 中给出“使用未声明的类型 URL”错误
【发布时间】:2016-07-07 13:15:58
【问题描述】:

当我在我的 swift 类中实现 func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Boolfunc textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool 方法时,它会给出如下所示的错误和警告。

错误:Use of undeclared type 'URL'

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

如果我将类名更改为NSURL 而不是URL,它会正确编译,但警告永远不会响起。

在我的 textView 中与 URL 交互时也不会调用上述方法

谢谢!

【问题讨论】:

    标签: ios swift3 xcode8


    【解决方案1】:

    试着把方法头改成这样:

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

    (形参url需要小写。)

    这绝对是 Swift/Xcode 的错误。形参URLURL 类型的影子。

    【讨论】:

    • 是的,你是对的,错误在 UITextViewDelegate 方法中。感谢您的工作!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    相关资源
    最近更新 更多