class property list in swift

42 Views Asked by At

I've got a class:

public class Circle: Shape {

  public var radius: Double = 0.0

  public var diameter: Double {
      get {
          return 2 * radius
      } set {
          radius = newValue / 2

      }
  }
  public var area: Double {
      get {
          return π * radius * radius
      } set {
          radius = sqrt(newValue / π)
      }
  }

  public var perimeter: Double {
      get {
          return radius * π * π
      } set {
          radius = perimeter/(π * π)
      }
  }

and now when I try getting all the class properties with Mirror, like that:

public var description: String {
    let properties = Mirror(reflecting: self).children
    for (label, value) in properties {
        str += label! + "\t\(value)\n"
    }
    return str
}

it somehow only takes the property of radius in account... Does someone know why the properties with getters and setters are being ignored and how I can include them?

Thanks!

0

There are 0 best solutions below