Bird
0
0

Which SwiftUI code snippet correctly creates a SecureField bound to a @State variable named userPassword with placeholder text "Password"?

easy📝 Conceptual Q2 of 15
iOS Swift - User Input and Forms
Which SwiftUI code snippet correctly creates a SecureField bound to a @State variable named userPassword with placeholder text "Password"?
ASecureField(text: $userPassword, placeholder: "Password")
BSecureField(text: userPassword, "Password")
CSecureField("Password", text: userPassword)
DSecureField("Password", text: $userPassword)
Step-by-Step Solution
Solution:
  1. Step 1: Recall SecureField syntax

    The correct initializer is SecureField(_ titleKey: String, text: Binding).
  2. Step 2: Check binding usage

    The text parameter must be bound using $ to the @State variable.
  3. Final Answer:

    SecureField("Password", text: $userPassword) -> Option D
  4. Quick Check:

    Binding uses $ prefix [OK]
Quick Trick: Use $ to bind @State variable in SecureField [OK]
Common Mistakes:
  • Omitting $ for binding
  • Swapping parameter order
  • Passing variable instead of binding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes