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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -