Bird
0
0

What is wrong with this SwiftUI TextField declaration? @State private var city = "" var body: some View { TextField(text: $city, "Enter city") }

medium📝 Debug Q7 of 15
iOS Swift - User Input and Forms
What is wrong with this SwiftUI TextField declaration? @State private var city = "" var body: some View { TextField(text: $city, "Enter city") }
AParameters are in wrong order; placeholder should come first
BMissing @Binding before city
CTextField cannot have empty initial value
DTextField requires a label view, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct parameter order for TextField

    Placeholder string comes first, then text binding.
  2. Step 2: Compare with code

    Code has text binding first, then placeholder string, which is incorrect.
  3. Final Answer:

    Parameters are in wrong order; placeholder should come first -> Option A
  4. Quick Check:

    TextField syntax: placeholder first, then binding [OK]
Quick Trick: Placeholder string always comes before text binding [OK]
Common Mistakes:
  • Swapping parameter order
  • Confusing @State with @Binding
  • Thinking initial value can't be empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes