Protocols mutating methods requirements in Swift
Forums:
protocol Сhain {
mutating func next()
}
enum Season: Int, Сhain {
case Summer, Fall, Winter, Spring
mutating func next() {
let value = (self.rawValue + 1) % 4
self = Season(rawValue: value)!
}
}
var season = Season.Winter
season.next()
season.next()
//season is .Summer
- Log in to post comments