Textfield QuickType Suggestions and Validation

My question is in regards to implementing a text field that both disallows invalid input *and* allows filling valid text via the QuickType suggestions. For simplicity, let's say my scenario is a text field that asks a user to input an email address. We don't want to allow the user to enter invalid text. For an email address, invalid text includes anything with a space since that's an invalid email address. The way I've always done this is to implement UITextFieldDelegate's textField(shouldChangeCharactersIn:replacementString:) method. If the new constructed text includes a space then it's disallowed.


The problem occurs when this text field is configured with an email address text content type. In this case, iOS suggests my email address. This is fine. But, when tapping my email address to fill it in iOS does the following:

  1. It calls textField(shouldChangeCharactersIn:replacementString:) first with the string parameter being a single space.
  2. It calls textField(shouldChangeCharactersIn:replacementString:) again with the suggested email address as the string.


The problem is, if we're not allowing spaces to be entered then we return false in step 1 above. This prevents it from continuing to prefill the email address. I understand why it's calling this method twice since it has to replace the existing text with the new text (though that strictly wouldn't require two changes). My question is- how does one implement text input validation while *also* allowing filling of the QuickType suggestions? Is there any way to tell the incoming text is coming from QuickType? Have I been doing validation all wrong this whole time? Any suggestions appreciated.