1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30
yattee/Extensions/CaseIterable+Next.swift

16 lines
411 B
Swift
Raw Normal View History

extension CaseIterable where Self: Equatable {
2021-07-08 04:09:18 +05:30
func next(nilAtEnd: Bool = false) -> 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)
2021-07-08 04:09:18 +05:30
if nilAtEnd == true {
if next == all.endIndex {
return nil
}
}
return all[next == all.endIndex ? all.startIndex : next]
}
}