Nico Nico - 3 months ago 7
iOS Question

Enum case '...' is not a member of type '...'

I have an enum:

enum State {
case FullOpen
case HalfOpen
case Closed
}


and this code:

var stateForConversionView: State!
...


var previousState: State!

if true {
previousState = stateForConversionView!
switch previousState {
case .FullOpen:
stateForConversionView = .HalfOpen
case .HalfOpen:
stateForConversionView = .FullOpen
case .Closed:
stateForConversionView = .HalfOpen
default:
break
}
}


I got an error on each switch statement:

Enum case 'FullOpen' not found in type 'State!'
Enum case 'HalfOpen' not found in type 'State!'
Enum case 'Closed' not found in type 'State!'


I don't really understand why. Can someone explain me please?

Answer

This way It will work fine :

if true {
    previousState = stateForConversionView

    switch previousState! {
    case .FullOpen:
        stateForConversionView = .HalfOpen
    case .HalfOpen:
        stateForConversionView = .FullOpen
    case .Closed:
        stateForConversionView = .HalfOpen
    default:
        break
    }
}

You need to add !.

Comments