If you accept One-time password (OTP) via SMS/text in your app, there's a nice goodie in
UITextInputTraits (which is inherited by
UIKeyInput which is in turn inherited by
UITextInput) which is adopted by
In short, you can do:
let textField = UITextField() textField.textContentType = .oneTimeCode
let textView = UITextView() textView.textContentType = .oneTimeCode
and when you receive the OTP via SMS/text, iOS will automatically show the OTP code in the QuickType bar for a few minutes letting you tap on it to automatically fill it into the textField/textView for you.
This is available since iOS 12. There's a few more types available in
UITextContentType such as
.newPassword that is quite useful.