I am attempting to create a serializer that will change the properties of an object.
Example:
class testobj{
var prop1:Int = 3
var prop2:String = "Hello"
var prop3:Dictionary<String,String> = Dictionary<String,String>()
}
I know I can access the names and types of the properties using
reflect(testobjc())[0].1
and
var tester = testobj()
_std_lib_DemangledTypeName(tester.prop1)
but what I would like to do is something like
var tester = testobj()
for(var x:Int = 0; x < reflect(testobj()).count; x++){
if(_std_lib_DemangledTypeName(tester.(reflect(testobj())[0].1)) == "Swift.String"){
tester.(reflect(testobj())[0].1) = "World!"
}
}
Essentially, I want to loop through all the properties listed for a given class and set the properties on a newly created object of that class. Any guidance would be appreciated. Swift reflection is new to me.
You could use this class to create a dictionary form an object and an object from a dictionary. https://github.com/evermeer/EVReflection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With