UIDatePicker crashes on setting maximumDate in iOS 16.0

Hi

My app is continuously crashing while setting maximumDate in date picker, this happens only with new iOS 16.0.

I am trying to set minimum and maximum date limit on date picker for accepting birth date, i.e. minimum age 18 years.

Crashing on this line: datePicker.maximumDate = maxDate

Detailed code: var components: DateComponents = DateComponents()

components.calendar = calendar

components.year = -18

let maxDate: Date = calendar.date(byAdding: components, to: currentDate)!

datePicker.maximumDate = maxDate

Please note, this code works fine in lower version than iOS 16.0.

Xcode: Version 14.0

macOS Monterey Version 12.6

iOS 16.0

I think I'm avoiding this crash by setting up the picker with both maximum and minimum dates before I set the default picked date.

UIDatePicker crashes on setting maximumDate in iOS 16.0
 
 
Q