Skip to content

Instantly share code, notes, and snippets.

@pookjw
Created February 3, 2026 13:45
Show Gist options
  • Select an option

  • Save pookjw/5863bd129d97db9142324d7c305ea71a to your computer and use it in GitHub Desktop.

Select an option

Save pookjw/5863bd129d97db9142324d7c305ea71a to your computer and use it in GitHub Desktop.
struct MyDef {
subscript(value: Int) -> Int {
return value
}
}
let def = MyDef()
let keyPath: KeyPath<MyDef, Int> = \MyDef.[3]
print(def[keyPath: keyPath]) // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment