json - Can I set values for a Swift object properties using mirroring? -
right can inspect variables of object using mirror type. can set values variables using mirroring? or maybe there's pure-swift way?
for example, i'd create object (a swift struct) json. possible without subclassing nsobject , using objective-c functions that?
this best can @ moment. still missing converting mirrorobject generic type. fyi using swiftyjson
func converttoobject<t>(json: json, genericobject: t) -> t { let mirroredobject = mirror(reflecting: genericobject) (_, var attr) in mirroredobject.children.enumerate() { if let propertyname = attr.label string! { attr.value = json[propertyname] print(propertyname) print(attr.value) } } // figure out how convert object type... }
Comments
Post a Comment