在swift中反射是這麼做的
struct Test
{
var t1 : String
var t2 : Int
func function()
{
}
}
let t = Test(t1: "t1", t2: 1)
let mirror = Mirror(reflecting: t)
for (key,value) in mirror.children
{
print(key as Any,value)
}
print(mirror.displayStyle as Any)
print(mirror.subjectType)
print(mirror.customMirror)
print(mirror.superclassMirror as Any)
複製程式碼