Skip to content

Instantly share code, notes, and snippets.

@vhart
Created June 9, 2018 03:49
Show Gist options
  • Save vhart/4b13296be2c1d43fe2889f99f1a05cf5 to your computer and use it in GitHub Desktop.
Save vhart/4b13296be2c1d43fe2889f99f1a05cf5 to your computer and use it in GitHub Desktop.
struct MyStruct {
let name: String
let number: Int
var bool: Bool
}
let instance = MyStruct(name: "Korg", number: 1, bool: true)
// Referencing
let nameRef: KeyPath<MyStruct, String> = \MyStruct.name
// Evaluating
let name = instance[keyPath: nameRef] // "Korg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment