enum
enum Weather { case sun, rain, wind, snow, unknown } let forecast = Weather.sun switch forecast { case .sun: print("It should be a nice day.") case .rain: print("Pack an umbrella.") case .wind: print("Wear something warm") case .snow: print("School is cancelled.") case .unknown: print("Our forecast generator is broken!") } |
String
let place = "Metropolis" switch place { case "Gotham": print("You're Batman!") case "Mega-City One": print("You're Judge Dredd!") case "Wakanda": print("You're Black Panther!") default: print("Who are you?") } |
Int
let day = 5 switch day { case 5: print("5 golden rings") fallthrough case 4: print("4 calling birds") case 3: print("3 French hens") case 2: print("2 turtle doves") default: print("A partridge in a pear tree") } |
5 golden rings 4 calling birds ♠ fallthrough 에 의해 아래 case 4까지 실행 |