1

我有一堂课:

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/(π * π)
      }
  }

现在,当我尝试使用 Mirror 获取所有类属性时,如下所示:

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

它以某种方式只考虑了半径的属性......有人知道为什么带有getter和setter的属性被忽略以及我如何包含它们?

谢谢!

4

0 回答 0