Last active
September 4, 2017 13:05
-
-
Save yoxisem544/32caf68d07534c1d886fb15496ff046e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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