mardi 1 décembre 2015

Is there any way to get the list of attributes of a class without any instantiated object?

I already know that we can get the list of attributes of a object using reflection in Swift, but all the examples that I found and have implemented so far uses a instantiate object. Something like that:

func attributeList() -> [String] {

    var attributeList = [String]()
    let serializableMirror = Mirror(reflecting: self) //using instantiate object

    for childMirror in serializableMirror.children {            
        if let label = childMirror.label {
            attributeList.append(label)
        }
    }
    return attributeList
}

My question is, there is any way to get the attributes of a class without any reference to it? Some kind of static method where I pass my desired class type and get the attributes list of it.





Aucun commentaire:

Enregistrer un commentaire