Bird
0
0

You want a Picker to show a list of colors from an array and update a selectedColor variable. Which approach is correct?

hard📝 Application Q9 of 15
iOS Swift - User Input and Forms
You want a Picker to show a list of colors from an array and update a selectedColor variable. Which approach is correct?
ACreate multiple Pickers, one for each color
BUse ForEach over the array inside Picker and bind selection to selectedColor
CUse DatePicker instead of Picker for colors
DBind selection to a constant color value
Step-by-Step Solution
Solution:
  1. Step 1: Understand dynamic Picker content

    ForEach allows creating Picker options from an array dynamically.
  2. Step 2: Bind selection to a variable to track choice

    Binding to selectedColor updates the variable when user picks a color.
  3. Final Answer:

    Use ForEach over the array inside Picker and bind selection to selectedColor -> Option B
  4. Quick Check:

    Use ForEach and binding for dynamic Picker [OK]
Quick Trick: Use ForEach inside Picker for dynamic lists [OK]
Common Mistakes:
  • Creating multiple Pickers unnecessarily
  • Using DatePicker for non-date data
  • Binding to constant disables selection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes