我上课了:
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的属性被忽略以及我如何包含它们?
谢谢!