How to Make Text Selectable in SwiftUI

October 13, 2025·2 min read·by dockui

How to Make Text Selectable in SwiftUI

Making text selectable in SwiftUI became much easier starting in iOS 15.
Before that, developers had to use UIKit workarounds with UITextView, but now Apple’s .textSelection() modifier makes any SwiftUI text selectable with just one line of code.

The .textSelection() Modifier (iOS 15+)

Starting in iOS 15, Apple added a new modifier to SwiftUI:

Code Snippet

When applied, users can long-press and select text, just like they would in Safari, Notes, or Messages.

Basic Example — Make Text Selectable

Here’s the simplest way to make text selectable in SwiftUI:

Code Snippet

Result:

Users can select and copy the first text, while the second remains static.

Example: Selectable Text with Multiple Views

You can apply .textSelection(.enabled) to a parent view, and all nested text inside will become selectable automatically.

Code Snippet

In this example, you don’t have to apply the modifier to each Text individually — adding it to the container view applies it to all.

Using Conditional Text Selection

If you only want text to be selectable under certain conditions (for example, when editing is enabled), you can control it dynamically:

Code Snippet

Try toggling the switch — it instantly enables or disables text selection.

Code copied to clipboard!