[ad_1]
Im making an attempt to make a day picker for a calendar kind app, however deciding on the day does not work for some motive. (I’ve feedback on the place the code breaks).
I’ve these two variables to maintain monitor:
@State var currentDate = Date()
@State var selectedDate = Date()
(I believe the issue comes from my use of the ForEach loop however I am unsure)
ForEach(0..<100) { day in
if (selectedDate == (currentDate + TimeInterval((86400 * day)))) {
Button {
selectedDate = (currentDate + TimeInterval((86400 * day)))
// error right here
} label: {
ZStack {
VStack {
Textual content("((currentDate + TimeInterval((86400 * day))).formatted(.dateTime.day()))")
.foregroundColor(.white)
Textual content("((currentDate + TimeInterval((86400 * day))).formatted(.dateTime.weekday(.brief)))")
.foregroundColor(.white)
}
}
}
} else {
Button {
selectedDate = (currentDate + TimeInterval((86400 * day)))
// and right here
} label: {
ZStack {
VStack {
Textual content("((selectedDate + TimeInterval((86400 * day))).formatted(.dateTime.day()))")
.foregroundColor(.white)
Textual content("((selectedDate + TimeInterval((86400 * day))).formatted(.dateTime.weekday(.brief)))")
.foregroundColor(.white)
}
}
}
}
}
[ad_2]
