I need to show a certain view on a certain day, so tried to do it based on date, but it doesn't work, pleas help me to solve this problem
...
func UpdateData() {
let current = Calendar.current
let date = current.component(.day, from: self.date)
let weekDay = current.component(.weekday, from: self.date)
let day = current.weekdaySymbols[weekDay - 1]
self.data = DateType(Day: day, Date: "\(date)")
}
struct DateType {
var Day: String
var Date: String
}
var body: some View {
ZStack {
if self.data.Day == DAY_1 {. // <- here is my if statement
WorkOutView()}
}
}
Ok so let me start with the basics -
First and foremost rule, if you need to update any view you need to use
source of truthand which is@State, but we can usesource of truthin the child views through different properties like@ObservedObject, @Binding,@StateObject.So, in your code the thing is missing source of code, which needs to update the views.
So if you want to change the view based on day, then you need to initialize like this
If needed then change below code too, if changing only above code works then you are good to go.