How to Make Text Selectable in SwiftUI
October 13, 2025·2 min read·by dockui

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

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.

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

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.
Code copied to clipboard!