yattee/Extensions/CaseIterable+Next.swift
2021-06-26 11:49:42 +02:00

9 lines
267 B
Swift

extension CaseIterable where Self: Equatable {
func next() -> Self {
let all = Self.allCases
let index = all.firstIndex(of: self)!
let next = all.index(after: index)
return all[next == all.endIndex ? all.startIndex : next]
}
}