ios – Im making an attempt to make a day picker for a calendar kind app, however choosing the day does not work for some purpose. (I’ve feedback on the place the code breaks)

[ad_1]

Im making an attempt to make a day picker for a calendar kind app, however choosing the day does not work for some purpose. (I’ve feedback on the place the code breaks).

The problem is that the variable selectedDate does not replace.

Principally the code has a loop from 0 to 100 days, and I simply multiply present date by the iterator to get 100 future dates. I want the code to alter selectedDate to no matter date I decide from the listingenter image description here

I’ve these two variables to maintain observe:

@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(.quick)))")
                                                    .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(.quick)))")
                                                    .foregroundColor(.white)
                                            }
                                        }
                                    }
                                }
                                
                                }

[ad_2]

Leave a Reply