[swift-users] Checking for a specific enum case and value

Kristof Liliom macandor.nullbit at gmail.com
Tue Dec 29 05:37:02 CST 2015


Hi,

What is the best way to do a one line check for an enum with a specific inner value? Example:

enum State {
	case Running, Stopped(Int32)
}

func stoppedSuccessfully(state: State) -> Bool {
	return state == .Stopped(0) // So only return true if state is .Stopped and the inner value is 0
}

Thank You,
Chris



More information about the swift-users mailing list