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.

Similar Blogs

View All Articles
SwiftUI: How To Reset a Form

SwiftUI: How To Reset a Form

Learn how to reset a SwiftUI form with one line. Clear text fields instantly using @State or a form model. Simple copy/paste SwiftUI code examples.

by dockui
Nov 10
SwiftUI: How To Toggle a Switch Programmatically

SwiftUI: How To Toggle a Switch Programmatically

Learn how to toggle a SwiftUI switch programmatically with @State and @Binding. Simple examples with code to trigger Toggle from buttons or other views.

by dockui
Nov 10
How to use @AppStorage in SwiftUI

How to use @AppStorage in SwiftUI

Learn how to use @AppStorage in SwiftUI to save user settings and preferences easily with UserDefaults

by dockui
Oct 17
How to Navigate to Another View in SwiftUI

How to Navigate to Another View in SwiftUI

Starting from iOS 16, Apple introduced the new NavigationStack API, which replaces NavigationView and makes navigation more powerful and reliable.

by dockui
Oct 13

Code copied to clipboard!