yattee/Extensions/CaseIterable+Next.swift

9 lines
267 B
Swift
Raw Normal View History

extension CaseIterable where Self: Equatable {
func next() -> Self {
let all = Self.allCases
2021-06-26 09:39:35 +00:00
let index = all.firstIndex(of: self)!
let next = all.index(after: index)
return all[next == all.endIndex ? all.startIndex : next]
}
}