Skip to content

Instantly share code, notes, and snippets.

@wildthink
Last active May 17, 2018 09:56
Show Gist options
  • Save wildthink/32f3680e0b690c2254fa4f8615d77e23 to your computer and use it in GitHub Desktop.
Save wildthink/32f3680e0b690c2254fa4f8615d77e23 to your computer and use it in GitHub Desktop.
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