import Foundation public protocol FocusableField: Hashable { var next: Self? { get } } extension FocusableField where Self: CaseIterable, Self: Equatable { public var next: Self? { guard let index = Self.allCases.firstIndex(of: self) else { return nil } let endIndex = Self.allCases.endIndex let nextIndex = Self.allCases.index(after: index) guard nextIndex < endIndex else { return nil } return Self.allCases[nextIndex] } }