-2

Hello after updating to Xcode 14 I'm facing with an issue on date picker so when I pick some date sometime date would be formatted like: 25 sep 2022 other times 30/09/2022 in Xcode 13 it was working fine

DatePicker("transactionDate", selection: $vm.transactionDate, displayedComponents: [.date])
.labelsHidden()
.id(vm.transactionDate)
.onChange(of: vm.transactionDate) { date in
 vm.selectedEndRecurrenceDate = date
}
}
.datePickerStyle(CompactDatePickerStyle())

So I don't understand now how to fix, nothing is changed in the code

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • Could you describe what you mean with _other times_, is it for other users or something else that differs between each occasion it changes? Can you reproduce this? – Joakim Danielson Sep 25 '22 at 15:04
  • It differs each time I choose a new date with the picker change the format seams randomly – Nicola Rigoni Sep 25 '22 at 21:09
  • how do you display the date? Dates are formatted when you display it, otherwise it is just `A specific point in time, independent of any calendar or time zone.`. Show a reproducible example code, so we can test it. – workingdog support Ukraine Sep 25 '22 at 22:53

1 Answers1

0

Adding an .id() modifier to your picker was a workaround for an old bug, see this question

When testing this in Xcode 14.1 beta (iOS) in the simulator I can reproduce the issue when I have the id modifier but as soon as I remove it the picker works fine

So it seems the hack to workaround the previous bug now creates a bug! So simply remove the .id() modifier since it isn't useful here.

DatePicker("transactionDate", selection: $vm.transactionDate, displayedComponents: [.date])
    .labelsHidden()
    .onChange(of: vm.transactionDate) { date in
        vm.selectedEndRecurrenceDate = date
    }
}
.datePickerStyle(CompactDatePickerStyle())
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52