Swift中的反射

丟的錢找到了發表於2018-03-25

在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)


複製程式碼

相關文章