2

I found two methods in UITextViewDelegate that available in iOS 10 or newer.

I seem them has difference type of second parameter (URL or NSTextAttachment).

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

optional func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool

When I use selector:

#selector(self.textView(_:shouldInteractWith:in:interaction:)

These two method has same syntax to defined a selector, so, how to discriminate them and how to fix error Ambiguous use of 'textView(_:shouldInteractWith:in:interaction:)' ?

Thanks for any help!

Tuesleep
  • 119
  • 13
  • If you have written code just convert it in to swift 3.0 code using editor -> convert – Dhruv Khatri Sep 18 '16 at 07:08
  • Already converted to swift 3.0, but build error yet. >_ – Tuesleep Sep 18 '16 at 07:37
  • 3
    You simply have to cast the methods to disambiguate (e.g `#selector(self.textView(_:shouldInteractWith:in:interaction:) as (UITextView, URL, NSRange, UITextItemInteraction) -> Bool)`), see for example [this Q&A](http://stackoverflow.com/questions/35658334/how-do-i-resolve-ambiguous-use-of-compile-error-with-swift-selector-syntax) on how to resolve selector ambiguities. – Hamish Sep 18 '16 at 08:16
  • @Hamish Good solved! Thanks. – Tuesleep Sep 18 '16 at 08:48
  • 1
    This doesn't work anymore in Swift 5 – Afonso May 17 '19 at 03:20

0 Answers0