Bird
0
0

Why does SwiftUI's TextField require a binding to a @State or @Binding variable instead of a simple String?

hard📝 Conceptual Q10 of 15
iOS Swift - User Input and Forms
Why does SwiftUI's TextField require a binding to a @State or @Binding variable instead of a simple String?
ABecause TextField cannot display static text
BTo allow two-way data flow between UI and data model
CTo prevent the user from editing the text
DBecause String variables are immutable in Swift
Step-by-Step Solution
Solution:
  1. Step 1: Understand data flow in SwiftUI

    SwiftUI uses bindings for two-way communication between UI and data.
  2. Step 2: Explain why simple String is insufficient

    Simple String is one-way; binding allows UI to update data and vice versa.
  3. Final Answer:

    To allow two-way data flow between UI and data model -> Option B
  4. Quick Check:

    TextField needs binding for two-way data flow [OK]
Quick Trick: Binding enables UI and data to stay in sync [OK]
Common Mistakes:
  • Thinking String is immutable
  • Believing TextField shows static text only
  • Confusing binding with immutability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes