In Swift, KeyPath allows you to access properties of a struct or class:
struct User {
let id: Int
var name: String
}
\User.id // KeyPath<User, Int>
\User.name // WritableKeyPath<User, String>
However, you cannot use standard key paths to refer to enum cases:
enum UserAction {
case home(HomeAction)
case settings(SettingsState)
}
\UserAction.home // 🛑 Error: key path cannot refer to static member 'home'
CasePaths provides CaseKeyPath to solve this limitation, enabling dot-chaining and generic access to enum case data.