Bird
0
0

Examine the following SwiftUI code snippet. What is the issue?

medium📝 Debug Q6 of 15
iOS Swift - User Input and Forms
Examine the following SwiftUI code snippet. What is the issue?
@State var password: String

var body: some View {
  SecureField("Password", text: $password)
}
A@State variable 'password' is not initialized
BSecureField cannot bind to @State variables
CMissing placeholder text in SecureField
DThe body property must be marked with @ViewBuilder
Step-by-Step Solution
Solution:
  1. Step 1: Check @State variable declaration

    @State variables must be initialized; here 'password' lacks an initial value.
  2. Step 2: Validate SecureField usage

    Binding to $password is correct, and placeholder is provided.
  3. Final Answer:

    @State variable 'password' is not initialized -> Option A
  4. Quick Check:

    @State vars require initial values [OK]
Quick Trick: Always initialize @State variables [OK]
Common Mistakes:
  • Forgetting to initialize @State variables
  • Assuming SecureField can't bind to @State
  • Confusing placeholder with binding parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes