Modifying instance properties via reflection

Hello there, I’ll start by explaining my use case.

I have a protocol of a networking library, which has a required func used for mapping values of the conformed type to encode in JSON, to whom I’m trying to give a default implementation which maps values via reflection.

My model objects are those who conforms to this protocol, and for all these I have boilerplate code to map values (name of the stored property becomes the key and its value the value).

Is there any way, given an instance mirror, to modify values of the instance being mirrored?

Also, for enums properties, I have to do custom transform to encode the rawValue as the value of its key, but given that the value of the child property in the mirror’s children is of type Any, how may I compare it is an enum?

Any help greatly appreciated.