Enumerations and the Switch Statement, p. 39

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!!")
}

Ibex, thanks a lot!

Trying to work with Apple’s Swift Language Ibook and “Cocoa Programming For OS X”, and getting a bit muddled in the translations sometimes.

I appreciate the hand!

Regards,

Steve O’Sullivan
public key http://pgp.mit.edu/pks/lookup?op=get&search=0xDD72A23519BF69B5