I am trying to properly implement the range operation for the exercise at the top of page 39:
If I use either the … or … range operators, the playground throws an error.
Xcode 8 with Swift 3
let osxVersion: Int = (1...12)
switch osxVersion {
case 1...8:
print("Some big cat!")
case 9:
print("Mavericks")
case 10:
print("Yosemite")
case 11:
print("El Capitan")
case 12:
print("Sierra")
default:
print("Appledonttellmenuthin!!")
}
That’s a syntax error as you are trying to make an Int from a Range.
You can try this:
let osxVersion = 1...12
But then you will make the switch statement frown at you because the value type of osxVersion is not an Int but a Range.
Try this, instead:
let osxVersion = Int (arc4random_uniform (UInt32 (16)))
print (osxVersion)
//
switch osxVersion {
case 1...8:
print("Some big cat!")
case 9:
print("Mavericks")
case 10:
print("Yosemite")
case 11:
print("El Capitan")
case 12:
print("Sierra")
default:
print("Appledonttellmenuthin!!")
}