What does this print?
struct Counter {
var value: Int = 0 {
didSet {
print("Set to \(value)")
}
}
}
var c = Counter()
c.value = 5
c.value = 8
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
Set to 5 Set to 8
Explanation:
didSet observers run after a property value changes.
[/spoiler]