And beyond property access, it also enables other meaningful abstractions like PartialCasePath
and a theoretical CasePathIterable
protocol.
This ties in as a solution to the original Enum Quality of Life Improvements problem:
enum Navigation: CasePathIterable, Hashable {
case firstScreen(FirstScreenData)
case secondScreen(SecondScreenData)
// Compiler generated
static var allCasePaths: [PartialCasePath<Navigation>]
}
let navigationStep = Navigation.firstScreen([...])
// representing a case label
let unassociatedNavigationStep = \Navigation.secondScreen as PartialCasePath
// matching cases by label only
let isFirstScreen = navigationStep ~= \.firstScreen // true
let isSecondScreen = unassociatedNavigationStep == \.secondScreen // true
// counting total enum cases
let totalNavigationSteps = Navigation.allCasePaths.count // currently impossible to determine without hardcoding or dropping associated values