SecureField สำหรับรหัสผ่าน
ซ่อนข้อมูลนำเข้าที่มีความอ่อนไหวด้วย SecureField
SecureField สำหรับรหัสผ่าน เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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. 🎉
เรียนรู้ Swift ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 30
- บทเรียน
- 120
คำถามที่พบบ่อย
บทเรียน “SecureField สำหรับรหัสผ่าน” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “SecureField สำหรับรหัสผ่าน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “SecureField สำหรับรหัสผ่าน”
ซ่อนข้อมูลนำเข้าที่มีความอ่อนไหวด้วย SecureField คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “SecureField สำหรับรหัสผ่าน” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม
ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การผูก TextField กับสถานะ
- ชนิดแป้นพิมพ์และข้อความตัวอย่าง
- SecureField สำหรับรหัสผ่าน
- การตรวจสอบข้อมูลนำเข้าแบบสด