var x = 1
switch x {
case 0: // if x = 0
print("x = 0")
case 1: // if x = 1
print("x = 1")
default: // if x is not 0 nor 1
print("no x value")
}
let liveAlbums = 2
switch liveAlbums {
case 0:
print("You're just starting out")
case 1:
print("You just released iTunes Live From SoHo")
case 2:
print("You just released Speak Now World Tour")
default:
print("Have you done something new?")
}
for i in 1 ... 100 {
switch (i % 3, i % 5) {
case (0, 0):
print("FizzBuzz")
case (0, _):
print("Fizz")
case (_, 0):
print("Buzz")
default:
print(i)
}
}
switch (expression) {
case value1:
// statements
case value2:
// statements
...
...
default:
// statements
}
let info = ("Dwight", 38)
// match complete tuple values
switch info {
case ("Dwight", 38):
print("Dwight is 38 years old")
case ("Micheal", 46):
print("Micheal is 46 years old")
default:
print("Not known")
}