SecureField do haseł
Proszę ukrywać poufne dane wejściowe za pomocą SecureField.
SecureField do haseł to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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. 🎉
Często zadawane pytania
Czy lekcja „SecureField do haseł” jest bezpłatna?
Tak — pełny tekst „SecureField do haseł” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „SecureField do haseł”?
Proszę ukrywać poufne dane wejściowe za pomocą SecureField. Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?
Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „SecureField do haseł”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?
Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Powiązanie TextField ze stanem
- Typy klawiatury i symbole zastępcze
- SecureField do haseł
- Walidacja danych wejściowych na żywo