Bird
0
0

Identify the error in this SwiftUI Picker code:

medium📝 Debug Q6 of 15
iOS Swift - User Input and Forms
Identify the error in this SwiftUI Picker code:
Picker("Choose", selection: selectedOption) {
  Text("A").tag(0)
  Text("B").tag(1)
}
AMissing $ before selectedOption for binding
BTags must be strings, not integers
CPicker label must be a View, not a String
DPicker cannot have more than one Text inside
Step-by-Step Solution
Solution:
  1. Step 1: Check binding syntax

    Picker's selection parameter requires a binding, so $ is needed before variable.
  2. Step 2: Validate other parts

    Tags can be integers, label can be String, multiple Text views allowed.
  3. Final Answer:

    Missing $ before selectedOption for binding -> Option A
  4. Quick Check:

    Picker selection needs $variable binding [OK]
Quick Trick: Picker selection must be bound with $ [OK]
Common Mistakes:
  • Omitting $ for binding
  • Wrong tag types
  • Misunderstanding label parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes