iOS ● ● ○ Swift 6

Kodebits Day 91: Property Observer

Sep 13 2026
Practice properties with a short swift challenge.

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]


Further Reading