0

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.

James Futures
  • 69
  • 2
  • 5

0 Answers0