samedi 25 juillet 2015

Switch statement inside if statement

I am trying to have a switch statement inside of an if statement checking integers

if variable <= 3 {
    // code
    switch variable {
    case 0: 
        println("0 case")
    case 1: 
        println("1 case")
    case 2: 
        println("2 case")
    case 3: 
        println("3 case")
    default:
        println("error")
    }
}

But I am getting an error for each case

 Binary operator '~=' cannot be applied to operands of type 'Int' and 'Int?'

I do not understand why this wouldn't work.

Aucun commentaire:

Enregistrer un commentaire