Does Swift support this? Til now my understanding is that reflection only works with public members. Is it possible to get private/static members of a type?
Is there any way to get static var's in a type using Mirror?
If I believe what's written there: https://medium.com/@mahadshahib/debugging-swift-using-the-mirror-api-to-observe-private-variables-2345bf264818
answer is yes.
Well, it's partially true.
Playground:
print("class:")
let m1 = Mirror(reflecting: Some.self)
for child in m1.children { print(child.label ?? "", child.value) }
print("instance:")
let m2 = Mirror(reflecting: Some())
for child in m2.children { print(child.label ?? "", child.value) }
print("\n-=|E.O.F|=-")
class Some {
static let inst = Some()
private var n = 1234
var f = 1.234
}
Output:
class:
instance:
n 1234
f 1.234
Mirror can't mirror the static variable.