小智 5
这是我目前能做的最好的事情。它仍然缺少将mirrorObject转换回其通用类型。仅供参考,这是使用 SwiftyJSON
func convertToObject<T>(json: JSON, genericObject: T) -> T {
let mirroredObject = Mirror(reflecting: genericObject)
for (_, var attr) in mirroredObject.children.enumerate() {
if let propertyName = attr.label as String! {
attr.value = json[propertyName]
print(propertyName)
print(attr.value)
}
}
// Figure out how to convert back to object type...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3425 次 |
最近记录: |