How it works
TextInputAutocapitalization describes how a text-entry view should automatically capitalize the characters a person types. Use it to align the keyboard's capitalization behavior with the kind of content a field expects, so names start with capital letters while email addresses and other case-sensitive input stay exactly as typed. Reach for it whenever the default sentence-capitalization would fight the data — proper names, addresses, identifiers, or anything that must be entered verbatim.
Apply it with the textInputAutocapitalization(_:) modifier
You rarely construct a
TextInputAutocapitalizationvalue directly; instead you pass one to thetextInputAutocapitalization(_:)view modifier, which sets the capitalization style for the text input inside that view. In the example eachTextFieldcarries its own.textInputAutocapitalization(...), so the two fields can behave differently.Capitalize proper nouns with .words
The
.wordsstyle tells the keyboard to capitalize the first letter of every word, which suits names and titles. The "Full Name"TextFielduses.textInputAutocapitalization(.words)so each part of a person's name is capitalized as they type.Turn capitalization off with .never
The
.neverstyle suppresses automatic capitalization entirely, leaving the text exactly as entered. The "Email"TextFieldapplies.textInputAutocapitalization(.never)because an email address is case-sensitive and an unwanted leading capital would corrupt it.Choose from the standard capitalization styles
TextInputAutocapitalizationexposes a fixed set of static styles —.never,.words,.sentences, and.characters— that map to the system's capitalization behaviors. You select the one that matches the field's content; the example draws on.wordsand.never, while.sentencesand.characterscover prose and all-caps input.Pair it with keyboardType for the full input experience
Capitalization is one half of configuring a field; the other is the keyboard layout. The email field combines
.textInputAutocapitalization(.never)with.keyboardType(.emailAddress)so the entry surface is tuned for addresses both in capitalization and in the keys it offers.
.textInputAutocapitalization(.never) to .textInputAutocapitalization(.sentences) and watch the first letter you type get capitalized — exactly the behavior you want to avoid in an address.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TextInputAutocapitalizationDemo: View {
@State private var name = ""
@State private var email = ""
var body: some View {
Form {
TextField("Full Name", text: $name)
.textInputAutocapitalization(.words)
TextField("Email", text: $email)
.textInputAutocapitalization(.never)
.keyboardType(.emailAddress)
}
.padding()
}
}