0
0
iOS Swiftmobile~20 mins

SecureField for passwords in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SecureField Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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)
  }
}
AThe typed characters appear as dots or bullets, hiding the actual text.
BThe typed characters appear as plain text, visible to the user.
CThe SecureField shows asterisks (*) instead of the typed characters.
DThe SecureField does not accept any input and remains empty.
Attempts:
2 left
💡 Hint
SecureField is designed to hide the typed text for privacy.
lifecycle
intermediate
2: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)
AWhen the view containing the SecureField appears.
BOnly when the user presses the return key on the keyboard.
CContinuously as the user types each character.
DOnly after the SecureField loses focus.
Attempts:
2 left
💡 Hint
SecureField updates continuously as the user types, like TextField.
📝 Syntax
advanced
2: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.
ASecureField(text: $password, placeholder: Text("Enter password"))
BSecureField("Enter password", text: $password)
CSecureField($password, "Enter password")
DSecureField("Enter password", binding: $password)
Attempts:
2 left
💡 Hint
Check the official SwiftUI SecureField initializer syntax.
🔧 Debug
advanced
2: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()
  }
}
AThe password variable is not marked with @State, so it cannot be bound.
BThe SecureField requires a @Binding variable, but password is a constant.
CThe SecureField needs a TextField instead to update variables.
DThe padding modifier prevents the SecureField from updating the variable.
Attempts:
2 left
💡 Hint
Check how SwiftUI tracks changes in variables for UI updates.
🧠 Conceptual
expert
2: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?
ASecureField prevents the keyboard from showing predictive text and autocorrect.
BSecureField automatically encrypts the password before storing it in memory.
CSecureField disables copy-paste to protect the password from being copied.
DSecureField masks the input visually to prevent shoulder surfing and accidental exposure.
Attempts:
2 left
💡 Hint
Think about what users see when typing passwords.