mercredi 31 août 2016

Set value to model class properties swift

I know I can get the list of class properties using Mirror(reflecting:) but I can only print them. But what if I want to set properties to them and return the mirrored object.
Somwhat like this -

    let mirroredObj = Mirror(reflecting: User())
                for (index, property) in mirroredObj.children.enumerate() {
                        property.value = <SOME_VALUE>
                    }
    return mirroredObj  

Or maybe some totally different approach to do this?





Aucun commentaire:

Enregistrer un commentaire