iOS ● ○ ○ Swift 6

Kodebits Day 86: Computed Property

Sep 4 2026
Practice properties with a short swift challenge.

What is the output?

struct Rect {
  var width: Int
  var height: Int
  var area: Int {
    return width * height
  }
}
let r = Rect(width: 4, height: 5)
print(r.area)


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

20

Explanation:

Computed properties calculate values on access rather than storing them.

[/spoiler]


Further Reading