iOS ● ○ ○ Swift 6

Kodebits Day 31: Computed Property

May 29 2026
Practice properties with a short swift challenge.

What does this print?

struct Box {
  var w = 5
  var area: Int { w * w }
}
let b = Box()
print(b.area)


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

25

Explanation:

Computed properties calculate their value each time they’re accessed, rather than storing it.

[/spoiler]


Further Reading