---
title: "textView(_:shouldInteractWith:in:interaction:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextviewdelegate/textview(_:shouldinteractwith:in:interaction:)-5qha9"
---

# 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.

## Declaration

```swift
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 doc://com.apple.uikit/documentation/UIKit/UITextItemInteraction).

## Return Value

Return Value true if interaction with the text attachment should be allowed; false if interaction should not be allowed.

## Discussion

Discussion A text view calls this method if the user taps or long-presses the text attachment and its 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.

## See Also

### Deprecated

- [textView(_:shouldInteractWith:in:interaction:)](uikit/uitextviewdelegate/textview(_:shouldinteractwith:in:interaction:)-622ub.md)
- [textView(_:shouldInteractWith:in:)](uikit/uitextviewdelegate/textview(_:shouldinteractwith:in:)-97zx6.md)
- [textView(_:shouldInteractWith:in:)](uikit/uitextviewdelegate/textview(_:shouldinteractwith:in:)-98tho.md)
- [UITextItemInteraction](uikit/uitextiteminteraction.md)
