enum Traffic {
case light
case heavy
mutating func reportAccident() {
self = .heavy
}
}
var currentTraffic: Traffic = .light
currentTraffic. reportAccident()
// currentTraffic is now .heavy
Just like classes and structs, enumerations can have instance methods. If an instance method mutates the value of the enum, it needs to be marked mutating
Comments