Bird
0
0

What is wrong with this DatePicker usage?

medium📝 Debug Q7 of 15
iOS Swift - User Input and Forms
What is wrong with this DatePicker usage?
@State private var time = Date()
DatePicker("Select time", selection: $time, displayedComponents: .date)
ADisplayed components should be .hourAndMinute to pick time
BDatePicker cannot bind to @State variables
CLabel must be omitted for DatePicker
DDatePicker requires a range parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand displayedComponents parameter

    .date shows date picker; to pick time, use .hourAndMinute.
  2. Step 2: Check other options

    Binding to @State is correct, label is optional but allowed, range is optional.
  3. Final Answer:

    Displayed components should be .hourAndMinute to pick time -> Option A
  4. Quick Check:

    Use .hourAndMinute for time picker [OK]
Quick Trick: Use .hourAndMinute to pick time in DatePicker [OK]
Common Mistakes:
  • Using .date when time is needed
  • Thinking binding is invalid
  • Forgetting label is optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes