Instead of having autocompletedNewText.characters.count > expectedDigits inside an if-else block, it is additional to the following if-block: If there is an overflow of characters, the DetailInputTextField's delegate will be notified about this first and then the validation takes place.
Instead of setting nextTextField's text directly, rely on the existing logic in textField(_, shouldChangeCharactersInRange:_, replacementString:_) to change the text.
@JamesJSY
autocompletedNewText.characters.count > expectedDigits
inside an if-else block, it is additional to the following if-block: If there is an overflow of characters, the DetailInputTextField's delegate will be notified about this first and then the validation takes place.textField(_, shouldChangeCharactersInRange:_, replacementString:_)
to change the text.