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]