Switch condition evaluates to a constant in Swift
Well, it basically means that the switch will always evaluate to menuIsClosed
. You probably meant something like this:
var currentSituation = aSituation // That would be a menuSituation (known at runtime)
// Also note that 'break' is not needed in (non-empty) match cases
switch currentSituation {
case .menuIsOpened:
println("Menu is opened")
case .menuIsClosed:
println("Menu is closed")
}
I had the same problem, the solution was to make the declaration globally:
import UIKit
enum menuSituation{
case menuIsOpened
case menuIsClosed
}
private var currentSituation: menuSituation = .menuIsClosed // globally declaration
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
switch currentSituation {
case .menuIsOpened:
println("Menu is opened")
break
case .menuIsClosed:
println("Menu is closed")
break
}
}
}