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)