我一直在这里寻找很多问题,我找到了一个类似标题
Enum case switch not found in type,但没有解决方案.
我想使用带有自身变异的枚举来解决问题,在个别状态下,下一个交通灯颜色是什么.
enum TrafficLights { mutating func next() { switch self { case .red: self = .green case .orange: self = .red case .green: self = .orange case .none: self = .orange } } }
我已将所有案例作为可能的选项,它仍然返回错误:
Enum ‘case’ not found in type ‘TrafficLights’
案例必须在函数之外声明:
enum TrafficLights { case green case red case orange case none mutating func next() { switch self { case .red: self = .green case .orange: self = .red case .green: self = .orange case .none: self = .orange } } }