Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created October 8, 2021 14:35
Show Gist options
  • Save mbrandonw/0c42c8e16d50b751cb2a6c7db341b02f to your computer and use it in GitHub Desktop.
Save mbrandonw/0c42c8e16d50b751cb2a6c7db341b02f to your computer and use it in GitHub Desktop.
struct Foo: Identifiable {
let id = 42
}
let kp1: KeyPath<Foo, Int> = idKeyPath()
let kp2: KeyPath<Foo, Int> = idKeyPath()
kp1 == kp2 // ✅ true
kp1 == \.id // ❌ false
kp2 == \.id // ❌ false
func idKeyPath<T: Identifiable>() -> KeyPath<T, T.ID> {
\.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment