Tuesday, September 27, 2022
HomeiOS Developmentios - Im attempting to make a day picker for a calendar...

ios – Im attempting to make a day picker for a calendar sort app, however deciding on the day would not work for some purpose. (I’ve feedback on the place the code breaks)


Im attempting to make a day picker for a calendar sort app, however deciding on the day would not work for some purpose. (I’ve feedback on the place the code breaks).

The difficulty is that the variable selectedDate would 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 monitor:

@State var currentDate = Date()
@State var selectedDate = Date()

(I believe the issue comes from my use of the ForEach loop however I am undecided)

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)
                                            }
                                        }
                                    }
                                }
                                
                                }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments