In iOS 12 Apple has introduced feature called Security Code AutoFill.
To use this in your app all you need to do is set UITextField‘s input view’s textContentType property oneTimeCode.
otpTextField.textContentType = .oneTimeCode
NOTE: Security Code AutoFill will only works with System Keyboard it will not work with custom keyboard.
WWDC video
When you get OTP it will look something like this:
