[Solved] swift properties setter not getting called


It looks to me like area is a computed property. Shouldn’t it be a read-only computed property? Seems to me that there are multiple triangles with a given area but different height/base values, so you can’t set the area in a meaningful way.

var area: Double {
  get { // getter
    return 0.5 * base * length
  }
}

You are also missing the /2 part of the area formula a = 1/2 b * h. That’s why your result is 20 when it should be 10.

1

solved swift properties setter not getting called