Bird
0
0

Which of the following is the correct syntax to create a SecureField bound to a @State variable named password with placeholder "Enter password"?

easy📝 Syntax Q12 of 15
iOS Swift - User Input and Forms
Which of the following is the correct syntax to create a SecureField bound to a @State variable named password with placeholder "Enter password"?
ASecureField("Enter password", text: $password)
BSecureField(text: $password, placeholder: "Enter password")
CSecureField("Enter password", binding: password)
DSecureField(text: password, placeholder: "Enter password")
Step-by-Step Solution
Solution:
  1. Step 1: Recall SecureField initializer

    The correct initializer is SecureField(_ titleKey: String, text: Binding).
  2. Step 2: Match syntax with variable

    Binding uses $password to connect the state variable.
  3. Final Answer:

    SecureField("Enter password", text: $password) -> Option A
  4. Quick Check:

    SecureField("text", text: $variable) = D [OK]
Quick Trick: Use $ before state variable for binding in SecureField [OK]
Common Mistakes:
  • Swapping parameter order
  • Missing $ for binding
  • Using wrong parameter names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes