I need is to show the main menu Monday to Friday and Saturday and Sunday a brunch menu. So I slip the view in two menus and I want to create a if statement that check-in which day and hours of the day we are and show the preselected menu.
Here’s a simple switch statement that will check the day.
Use the hour variable to check the hour:
or you can use another switch statement here for specific times.
Code Block Swift let dayOfWeek = Calendar.current.component(.weekday, from: Date()) let hour = Calendar.current.component(.hour, from: Date()) switch dayOfWeek { case 2...6: // weekday menu case 1, 7: // weekend menu default: print("Unknown day") }
Use the hour variable to check the hour:
Code Block Swift if hour < 12 { // morning } else { // afternoon }
or you can use another switch statement here for specific times.