How to use enum in Swift

1 Answer

0 votes
enum DayOfWeek {
    case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

func printDay(_ day: DayOfWeek) {
    switch day {
    case .MONDAY:
        print("It's Monday")
    case .TUESDAY:
        print("It's Tuesday")
    case .WEDNESDAY:
        print("It's Wednesday")
    case .THURSDAY:
        print("It's Thursday")
    case .FRIDAY:
        print("It's Friday")
    case .SATURDAY:
        print("It's Saturday")
    case .SUNDAY:
        print("It's Sunday")
    }
}

let today = DayOfWeek.SUNDAY

print(today)

printDay(today)



/*
run:

SUNDAY
It's Sunday

*/

 



answered Dec 20, 2024 by avibootz
...