Switch error: expected member name or constructor call - what's wrong?

I would like to include a switch in my 3 cases, but I get an error that I cannot solve:

Error: expected member name or constructor call after type name

I must have missed something because I already used the same code. But now I have an almost empty project and I can’t understand what happened?

import UIKit class ViewController: UIViewController { enum MyStateStatus { case Ready case Running case Stopped } @IBAction func actionPressed(sender: UIButton) { switch MyStateStatus { case MyStateStatus.Ready: print("I'm ready") default: print("other") } } 

I am using Swift, Xcode 6.3.2

UPDATE: Replace println() with print() for Swift 2.2 and Xcode 7 compatibility.

+5
source share
1 answer

In your example, you apply a switch to the enum declaration, but you need to switch the object containing one of the possible enumeration values.

For instance:

 var currentState: MyStateStatus = .Ready @IBAction func actionPressed(sender: UIButton) { switch currentState { case .Ready: println("I'm ready") default: println("other") } } 
+4
source

All Articles