1
0
mirror of https://github.com/yattee/yattee.git synced 2025-01-06 01:20:31 +05:30
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 15:09:35 +05:30
let index = all.firstIndex(of: self)!
let next = all.index(after: index)
return all[next == all.endIndex ? all.startIndex : next]
}
}