'UITextField in SwiftUI app: How to select all the text when user clicks the TextField
I'm working in SwiftUI and trying to use a UITextField because SwiftUI TextFields are still lacking.
I have a UIViewRepresentable with a Coordinator that conforms to UITextFieldDelegate.
This is what I've currently got inside the Coordinator:
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.selectedTextRange = textField.textRange(
from: textField.beginningOfDocument,
to: textField.endOfDocument)
}
I've also tried:
textField.selectAll(nil)
Neither of these options are producing any kind of selecting or highlighting. It still just places the cursor at the end of the text.
I'm sure it's something simple that I'm missing, but I'm feeling totally stumped.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
