0Pricing
SwiftUI Academy · Lesson

Keyboard Types & Placeholders

Configure keyboard, prompt, and submit behavior.

Keyboard Types & Placeholders is a free SwiftUI Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Shape the Input

A bare TextField accepts anything. With a few modifiers you can shape the keyboard, the hint, and what happens on submit. ⌨️

Choosing a Keyboard

The keyboardType modifier picks which on-screen keyboard appears. An email field deserves the email layout, not the full alphabet.

TextField("Email", text: $email)
  .keyboardType(.emailAddress)

Numbers Only

Asking for a phone or amount? Use .numberPad or .decimalPad so users get a clean number keyboard with no letters in the way.

TextField("Age", text: $age)
  .keyboardType(.numberPad)

Placeholder vs Prompt

The first string argument is the placeholder, the gray hint shown while the field is empty. It guides users without taking up extra space.

TextField("Search recipes", text: $query)

A Separate Prompt

You can also pass a prompt as its own argument. This keeps the visible label and the placeholder hint as two distinct pieces of text.

TextField("City", text: $city,
  prompt: Text("e.g. Tokyo"))

Capitalization Control

Use textInputAutocapitalization to decide how the keyboard capitalizes. Set it to .never for usernames so nothing is auto-uppercased.

TextField("Username", text: $user)
  .textInputAutocapitalization(.never)

Turning Off Autocorrect

For codes, handles, or URLs, autocorrect gets in the way. Add autocorrectionDisabled to let users type exactly what they mean.

TextField("Handle", text: $handle)
  .autocorrectionDisabled()

The Return Key Label

The submitLabel modifier changes the keyboard return key text. Use .search, .done, or .next to match what the field actually does.

TextField("Search", text: $query)
  .submitLabel(.search)

Reacting to Submit

The onSubmit modifier runs your code when the user taps return. It is the perfect place to start a search or move focus.

TextField("Search", text: $query)
  .onSubmit { runSearch() }

Stack the Modifiers

These modifiers chain freely. Combine keyboard type, capitalization, and submit label on one field to craft exactly the input you want.

Small Details, Big Polish

The right keyboard and a clear prompt feel effortless to users. These tiny touches are what make an app feel professional. ✨

Quick Check

Which modifier changes the keyboard that appears for a TextField?

Recap

You tuned a field with keyboardType, prompts, capitalization, and onSubmit. Small modifiers turn a plain box into thoughtful, friendly input. 🎉

Frequently asked questions

Is the “Keyboard Types & Placeholders” lesson free?

Yes — the full text of “Keyboard Types & Placeholders” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “Keyboard Types & Placeholders”?

Configure keyboard, prompt, and submit behavior. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Keyboard Types & Placeholders” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Binding a TextField to State
  2. Keyboard Types & Placeholders
  3. SecureField for Passwords
  4. Live Input Validation
← Back to SwiftUI Academy