SecureField for Passwords
Hide sensitive input with SecureField.
SecureField for Passwords is a free SwiftUI Academy lesson on CoddyKit — lesson 3 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.
Hiding Sensitive Text
Passwords should never appear on screen as plain letters. SwiftUI gives you SecureField, a text field that masks every character. 🔒
Just Like TextField
A SecureField works exactly like a TextField: a placeholder and a binding. The only difference is the dots shown instead of the real characters.
SecureField("Password", text: $password)It Still Needs State
Just like before, the typed value lives in a @State string. SecureField reads and writes it through the binding you pass with the $ prefix.
@State private var password = ""The Real Value Is Yours
The dots are only for display. Your state string holds the actual text, so you can validate or send it even though the screen hides it.
A Bordered Look
Give it the same polish as any field. The textFieldStyle modifier with .roundedBorder makes a clean, tappable password box.
SecureField("Password", text: $password)
.textFieldStyle(.roundedBorder)Pairing With Username
A login screen usually stacks a normal TextField for the email above a SecureField for the password, each with its own state.
TextField("Email", text: $email)
SecureField("Password", text: $password)Helping the System
Add textContentType(.password) so iOS offers saved passwords and Keychain suggestions, making sign-in faster for your users.
SecureField("Password", text: $password)
.textContentType(.password)New vs Existing Passwords
On a sign-up screen use .newPassword instead. iOS then suggests a strong, unique password and stores it in the Keychain.
SecureField("New password", text: $pw)
.textContentType(.newPassword)Reacting to Submit
SecureField supports onSubmit too. When the user taps return, run your login or move focus to the next field.
SecureField("Password", text: $pw)
.onSubmit { logIn() }Privacy by Default
Because the characters are masked, no one glancing at the screen sees the password. SecureField gives you that privacy for free.
Same Skills, Safer Field
Everything you learned about binding text still applies. SecureField is simply the safe choice whenever the input is a secret. ✨
Quick Check
What is the main difference between SecureField and TextField?
Recap
You masked secret input with SecureField, kept the real value in state, and used textContentType to help iOS suggest and save passwords. 🎉
Frequently asked questions
Is the “SecureField for Passwords” lesson free?
Yes — the full text of “SecureField for Passwords” 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 “SecureField for Passwords”?
Hide sensitive input with SecureField. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “SecureField for Passwords” 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
- Binding a TextField to State
- Keyboard Types & Placeholders
- SecureField for Passwords
- Live Input Validation