I have a date picker, when the fromDate and toDate sections changes, I would like to assign it to the myArray["fromDate"] = $fromDate, how do I do that, thank you for your time.
I tried with onTapGesture, but it crash the app when I'm selecting the dates.
var myArray["fromDate"] : [String: Any]
struct myDatePicker: View {
@State public var toDate = Date()
@State public var fromDate: Date = Calendar.current.date(byAdding: DateComponents(year: -1), to: Date()) ?? Date()
var body: some View {
HStack(spacing:10) {
VStack(alignment:.leading, spacing:10) {
Text("Service Date Range")
.font(.system(size: 16))
.bold()
.foregroundColor(.black)
HStack {
DatePicker(selection: $fromDate.onchange({ myArray["fromDate"] = $fromDate}), displayedComponents: .date) {
Text("From")
.font(.body)
.fixedSize()
}
DatePicker(selection: $toDate, in: ...Date(), displayedComponents: .date) {
Text("To")
.font(.body)
.fixedSize()
}
}
}
}.padding(10)
}
}
myArrayis defined or what type it is.myArray