Last active
May 17, 2018 09:56
-
-
Save wildthink/32f3680e0b690c2254fa4f8615d77e23 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public struct Person { | |
public var name: String | |
public var birthday: Date | |
// In years | |
public var age: Int { | |
return Calendar.current.dateComponents([.year], from: birthday, to: Date()).year! | |
} | |
} | |
// Create a Person and use a Waldo get and set some values | |
var mary = Person(name: "Mary", birthday: Date(timeIntervalSince1970: 0)) | |
let waldo = mary.waldo() | |
let age: Any = waldo.get("age") | |
waldo.set("name", to: "Mary Jane") | |
Swift.print (mary) // -> Person(name: "Mary") | |
Swift.print (waldo.value()!) // -> Person(name: "Mary Jane") | |
mary = waldo.value() // To update 'mary' with the updated Person struct |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment