Challenge - 5 Problems
SecureField Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the visible output of this SwiftUI SecureField?
Consider this SwiftUI code snippet for a password input. What will the user see when typing in the SecureField?
iOS Swift
import SwiftUI struct ContentView: View { @State private var password = "" var body: some View { SecureField("Enter password", text: $password) .padding() .border(Color.gray) } }
Attempts:
2 left
💡 Hint
SecureField is designed to hide the typed text for privacy.
✗ Incorrect
SecureField masks the input by showing dots or bullets instead of the actual characters to keep passwords private.
❓ lifecycle
intermediate2:00remaining
When does the SecureField update its bound variable in SwiftUI?
Given a SecureField bound to a @State variable, when is the variable updated with the user's input?
iOS Swift
SecureField("Password", text: $password)Attempts:
2 left
💡 Hint
SecureField updates continuously as the user types, like TextField.
✗ Incorrect
SecureField updates its bound variable continuously as the user types each character, enabling reactive UI updates.
📝 Syntax
advanced2:00remaining
Which SwiftUI code snippet correctly creates a SecureField with a placeholder and a bound variable?
Select the code that compiles and works as expected for a SecureField with placeholder "Enter password" and bound to @State variable password.
Attempts:
2 left
💡 Hint
Check the official SwiftUI SecureField initializer syntax.
✗ Incorrect
The correct initializer is SecureField(_ titleKey: StringProtocol, text: Binding). Option B matches this exactly.
🔧 Debug
advanced2:00remaining
Why does this SecureField not update the password variable?
Examine this code snippet. The SecureField does not update the password variable when typing. What is the cause?
iOS Swift
struct ContentView: View {
@State private var password = ""
var body: some View {
SecureField("Password", text: $password)
.padding()
}
}Attempts:
2 left
💡 Hint
Check how SwiftUI tracks changes in variables for UI updates.
✗ Incorrect
In SwiftUI, variables bound to input fields must be @State or @Binding to allow updates. Here, password is a plain variable, so binding fails.
🧠 Conceptual
expert2:00remaining
What is the main security benefit of using SecureField over TextField for password input?
Why should developers prefer SecureField instead of TextField when asking users for passwords?
Attempts:
2 left
💡 Hint
Think about what users see when typing passwords.
✗ Incorrect
SecureField hides the typed characters by showing dots or bullets, protecting the password from being seen by others nearby.