Clicky

iOS Dev Nugget 315 UITextContentType.oneTimeCode

.

Need to run a code review on your codebase? Hire me

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 UITextField and UITextView.

In short, you can do:

let textField = UITextField()
textField.textContentType = .oneTimeCode

or

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 .password, .newPassword that is quite useful.

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues