How to enable text selection in SwiftUI Text Views to copy it at runtime
Enabling selection of the text inside a Text View of SwiftUI
SOFTWARE DEVELOPMENTIOS DEVELOPMENTSWIFTUI
Eduardo Domínguez Menéndez
7/20/20241 min read
Let's start a new article of my coding school. By default, you may not be able to select the content (text) of a Text View in SwiftUI to trigger the typical context menu with options such as "Copy" or "Translate".
To enable menu with options such as "Translate" or "Copy", the required code snippet is quite simple: add the following modifier to the the Text View or to a hierarchy of views:
.textSelection(.enabled)
This behaviour is easy to apply but is easy to forget this modifier when you learn SwiftUI.
iPhone Charger with Fast Charging Capability, Type C Wall Charger
The most chargers the best ;)
Apple iPhone 16 Pro, US Version, 128GB, Black Titanium - Unlocked (Renewed)
The iPhone with the best trade off price versus features. This iPhone is ready for Apple Intelligence and it is equipped with LIDAR sensor for your AR Projects or visionOS projects.
Apple 2024 Mac Mini Desktop Computer with M4 chip with 10‑core CPU and 10‑core GPU
The best Mac trade off price versus performance and cutting edge features
Suggested stuff for a developer
The following items are a list of stuff that really help us in our daily workflows as developers. Buying through these Amazon links support this site.