<!--
{
  "availability" : [
    "iOS: 10.0.0 - 17.0.0",
    "iPadOS: 10.0.0 - 17.0.0",
    "macCatalyst: 13.1.0 - 17.0.0",
    "tvOS: 10.0.0 - 17.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextViewDelegate/textView(_:shouldInteractWith:in:interaction:)-5qha9",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextViewDelegate(im)textView:shouldInteractWithTextAttachment:inRange:interaction:"
  },
  "title" : "textView(_:shouldInteractWith:in:interaction:)"
}
-->

# textView(_:shouldInteractWith:in:interaction:)

Asks the delegate whether the specified text view allows the specified type of user interaction with the provided text attachment in the specified range of text.

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

## Parameters

`textView`

The text view containing the text attachment.

`textAttachment`

The text attachment.

`characterRange`

The character range containing the text attachment.

`interaction`

The type of interaction that is occurring (for possible values, see [`UITextItemInteraction`](/documentation/UIKit/UITextItemInteraction)).

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if interaction with the text attachment should be allowed; <doc://com.apple.documentation/documentation/Swift/false> if interaction should not be allowed.

## Discussion

A text view calls this method if the user taps or long-presses the text attachment and its [`image`](/documentation/UIKit/NSTextAttachment/image) property is not `nil`. You can use this method to trigger an action in addition to displaying the text attachment inline with the text.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)