I have this code
import UIKit
enum menuSituation{
case menuIsOpened
case menuIsClosed
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var currentSituation = menuSituation.menuIsClosed
switch(currentSituation){ //Here is the warning
case .menuIsOpened:
println("Menu is opened")
break
case .menuIsClosed:
println("Menu is closed")
break
}
}
In the line where I start to define switch statement, it gives me the warning :
Switch condition evaluates to a constant
How can I get rid of this warning?
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:
print("Menu is opened")
case .menuIsClosed:
print("Menu is closed")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With