Bird
0
0

Identify the issue in this SwiftUI Form code snippet:

medium📝 Debug Q7 of 15
iOS Swift - User Input and Forms
Identify the issue in this SwiftUI Form code snippet:
Form {
  Section(header: Text("Contact")) {
    TextField("Phone", text: phone)
  }
}
AForm requires at least two Sections
BSection header must be a string, not a Text view
CTextField cannot be used inside a Section
DThe <code>phone</code> binding is missing the <code>$</code> prefix
Step-by-Step Solution
Solution:
  1. Step 1: Check TextField binding

    The TextField requires a binding to a state variable with $ prefix.
  2. Step 2: Identify the error

    The code uses phone instead of $phone, which causes a compile error.
  3. Final Answer:

    The phone binding is missing the $ prefix -> Option D
  4. Quick Check:

    Binding variables need $ for two-way binding [OK]
Quick Trick: Use $ prefix for binding variables in TextField [OK]
Common Mistakes:
  • Omitting $ for binding variables
  • Misunderstanding Section header type
  • Thinking TextField is disallowed in Section

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes