Skip to content

Instantly share code, notes, and snippets.

@hitsvilleusa
Created January 15, 2015 22:38
Show Gist options
  • Save hitsvilleusa/30261790bb93cc872737 to your computer and use it in GitHub Desktop.
Save hitsvilleusa/30261790bb93cc872737 to your computer and use it in GitHub Desktop.
Chained Property Observers
struct Person {
var firstName: String = "" {
willSet {
println("Changing firstname from \(firstName) to \(newValue)")
}
}
}
struct Family {
var parent: Person = Person() {
willSet {
println("Changing the parent from \(parent.firstName) to \(newValue.firstName)")
}
}
var child: Person = Person() {
willSet {
println("Changing the child from \(child.firstName) to \(newValue.firstName)")
}
}
}
var family: Family = Family() {
willSet {
println("Changing family")
}
}
family.parent.firstName = "Chris"
family.parent.firstName = "Joe"
@randomstep
Copy link

I'm not even sure why I have this open, but is it meant to just continually crash playground? :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment