<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/textSelection(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE13textSelectionyQrqd__AA17TextSelectabilityRd__lF"
  },
  "title" : "textSelection(_:)"
}
-->

# textSelection(_:)

Controls whether people can select text within this view.

```
nonisolated func textSelection<S>(_ selectability: S) -> some View where S : TextSelectability
```

## Discussion

People sometimes need to copy useful information from [`Text`](/documentation/SwiftUI/Text) views —
including error messages, serial numbers, or IP addresses — so they
can then paste the text into another context. Enable text selection
to let people select text in a platform-appropriate way.

You can apply this method to an individual text view, or to a
container to make each contained text view selectable. In the following
example, the person using the app can select text that shows the date of
an event or the name or email of any of the event participants:

```
var body: some View {
    VStack {
        Text("Event Invite")
            .font(.title)
        Text(invite.date.formatted(date: .long, time: .shortened))
            .textSelection(.enabled)

        List(invite.recipients) { recipient in
            VStack (alignment: .leading) {
                Text(recipient.name)
                Text(recipient.email)
                    .foregroundStyle(.secondary)
            }
        }
        .textSelection(.enabled)
    }
    .navigationTitle("New Invitation")
}
```

On macOS, people use the mouse or trackpad to select a range of text,
which they can quickly copy by choosing Edit > Copy, or with the
standard keyboard shortcut.

![A macOS window titled New Invitation, with header Event Invite and](images/com.apple.SwiftUI/View-textSelection-1@2x.png)

On iOS, the person using the app touches and holds on a selectable
`Text` view to begin selecting text.
In iOS 27 or later, this brings up the system text selection handles
and highlight which supports selecting a range of text.
In iOS 26 or earlier, this brings up a system menu with
menu items appropriate for the current context.
These menu items operate on the entire contents of the `Text` view.

![A portion of an iOS view, with header Event Invite and the date](images/com.apple.SwiftUI/View-textSelection-2~dark@2x.png)

> Note: ``doc://com.apple.SwiftUI/documentation/SwiftUI/Button`` views don’t support text selection.

---

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)