<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextInteraction",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITextInteraction"
  },
  "title" : "UITextInteraction"
}
-->

# UITextInteraction

An interaction that provides text selection gestures and UI to custom text views.

```
@MainActor class UITextInteraction
```

## Overview

Use [`UITextInteraction`](/documentation/UIKit/UITextInteraction) to provide your custom text views the same text selection gestures and UI available in native text views like [`UITextView`](/documentation/UIKit/UITextView) and [`UITextField`](/documentation/UIKit/UITextField). When creating a text interaction, choose a mode that matches the state of the text, [`UITextInteractionMode.editable`](/documentation/UIKit/UITextInteractionMode/editable) or [`UITextInteractionMode.nonEditable`](/documentation/UIKit/UITextInteractionMode/nonEditable). Then set the [`textInput`](/documentation/UIKit/UITextInteraction/textInput) property to an object that conforms to [`UITextInput`](/documentation/UIKit/UITextInput), and add the interaction to a view.

```swift
// Create a selection interaction for non-editable content.
let selectionInteraction = UITextInteraction(for: .nonEditable)

// Assign `textInput` to your view that implements the `UITextInput` protocol
// to get more control over the selection behavior and the text input system.
selectionInteraction.textInput = customTextView

// Add the interaction to the view.
customTextView.addInteraction(selectionInteraction)
```

If your custom text view supports editable and non-editable text, create two interactions — one for each mode — and add the interaction that matches the state of text to the view while removing the other interaction.

```swift
override func becomeFirstResponder() -> Bool {
    let isFirstResponder = self.isFirstResponder
    let result = super.becomeFirstResponder()
    
    if isFirstResponder == false && self.isFirstResponder == true {
        customTextView.removeInteraction(nonEditableTextInteraction)
        customTextView.addInteraction(editableTextInteraction)
    }
    
    return result
}

override func resignFirstResponder() -> Bool {
    let isFirstResponder = self.isFirstResponder
    let result = super.resignFirstResponder()
    
    if isFirstResponder == true && self.isFirstResponder == false {
        customTextView.removeInteraction(editableTextInteraction)
        customTextView.addInteraction(nonEditableTextInteraction)
    }
    
    return result
}
```

If your app provides other gestures in the same view hierarchy, you can use the [`require(toFail:)`](/documentation/UIKit/UIGestureRecognizer/require(toFail:)) method to set up failure requirements between your app’s gestures and the text interaction gestures listed in the [`gesturesForFailureRequirements`](/documentation/UIKit/UITextInteraction/gesturesForFailureRequirements) property.

## Topics

### Creating text interactions

[`+  textInteractionForMode:`](/documentation/UIKit/UITextInteraction/init(for:))

Creates a text interaction with the specified mode.

### Handling text input and interaction events

[`textInput`](/documentation/UIKit/UITextInteraction/textInput)

The object that interacts with the text input system.

[`delegate`](/documentation/UIKit/UITextInteraction/delegate)

The object that receives events from the text interaction.

[`UITextInteractionDelegate`](/documentation/UIKit/UITextInteractionDelegate)

An interface that an object implements to receive information about text interaction events.

### Getting interaction information

[`gesturesForFailureRequirements`](/documentation/UIKit/UITextInteraction/gesturesForFailureRequirements)

The list of gestures that the text interaction adds to the view hierarchy.

[`textInteractionMode`](/documentation/UIKit/UITextInteraction/textInteractionMode)

The mode of the text interaction.

[`UITextInteractionMode`](/documentation/UIKit/UITextInteractionMode)

Modes that determine the selection behaviors that a text interaction provides.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`UIInteraction`](/documentation/UIKit/UIInteraction)

[`Hashable`](/documentation/Swift/Hashable)

---

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)