UITextFiled.selectedTextRange doesn't work

I want to put cursor (indicator point) to the end of text field.

I have the following code, but it does nothing

textField.selectedTextRange = textField.textRange(from: textField.endOfDocument, to: textField.endOfDocument)

Is there a way to put cursor to the end of text field?

As far as I tried it put cursor to the end of text field. Where have you put the line? Is the textField become first responder?

Yes, i put it in textField become first responder

I tried following code in the same place due to check if this is right place textField.selectedTextRange = textField.textRange(from: textField.beginningOfDocument, to: textField.endOfDocument) And it works - selects all text in text field

It seems to me selectedTextRange doesn't work if range has zero length

I tried following code in the same place Where is that same place?

Inside textFieldDidBeginEditing

UITextFiled.selectedTextRange doesn't work
 
 
Q