The .keyboardType() view modifier method in SwiftUI is used to specify the keyboard type from the UIKeyboardType enumeration to use for text entry.

Note: This method is specifically for use with text entry, so it can be applied as a view modifier to any view that accepts text input from the user, like a TextField.


TextField("Some label", text: $someValueBinding)

This method has one required parameter:

  • type: One of the keyboard types defined in the UIKeyboardType enumeration.


The following example demonstrates how to use the .keyboardType() method to ensure the user can enter a correctly formatted email address:

TextField("[email protected]", text: $emailAddress)

This will display:

SwiftUI ViewModifier KeyboardType


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn SwiftUI on Codecademy