In the application I need to set the condition that on a certain day of the week one variable will be true.
For example
if Calendar.day == monday {
var mon = true
}
I know that this is not right. But for now I do not quite understand how days of the week are. Please help me with this
Try out this. The dayInWeek string will present the current day of the week such as "Monday", or "Tuesday". The switch statement will check for what day it is, and you can perform a function when it is that subsequent day.
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayInWeek = dateFormatter.string(from: date)
switch dayInWeek {
case "Monday":
print("Today is Monday")
case "Tuesday":
print("Today is Tuesday")
default:
break
}
Of course, you'll finish it off for the rest of the days in the week.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With