Skip to content

Instantly share code, notes, and snippets.

@yoxisem544
Last active September 4, 2017 13:05
Show Gist options
  • Save yoxisem544/32caf68d07534c1d886fb15496ff046e to your computer and use it in GitHub Desktop.
Save yoxisem544/32caf68d07534c1d886fb15496ff046e to your computer and use it in GitHub Desktop.
struct Person {
var name: String
}
struct Book {
var title: String
var authors: [Person]
var primaryAuthor: Person {
return authors.first!
}
}
let abelson = Person(name: "Harold Abelson")
let sussman = Person(name: "Gerald Jay Sussman")
let book = Book(title: "Structure and Interpretation of Computer Programs", authors: [abelson, sussman])
book[keyPath: \Book.title]
// Key paths can drill down multiple levels
// They also work for computed properties
book[keyPath: \Book.primaryAuthor.name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment