79756328

Date: 2025-09-05 00:26:05
Score: 0.5
Natty:
Report link

I found that Apple is using bits masking to display the components. By adding these 3 statics variables, I was able to select only the components I needed.

extension DatePickerComponents {
    /// Second
    /// 0b10000000
    static let second =       DatePickerComponents(rawValue: 0b10000000)
    /// Day
    /// 0b00010000
    static let day =          DatePickerComponents(rawValue: 0b00010000)
    /// Month and year
    /// 0b00001100
    static let monthAndYear = DatePickerComponents(rawValue: 0b00001100)
}

Usage :

    DatePicker(
        "Month, year, hour and minutes",
        selection: $date,
        displayedComponents: [.monthAndYear, .hourAndMinute]
    ) // .hourAndMinute is already in DisplayedComponents.
    .datePickerStyle(.stepperField)
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jean-Charles