Skip to content

Instantly share code, notes, and snippets.

@harishgonnabattula
Last active December 29, 2015 19:17
Show Gist options
  • Save harishgonnabattula/87f76ccc1ae86e64b41d to your computer and use it in GitHub Desktop.
Save harishgonnabattula/87f76ccc1ae86e64b41d to your computer and use it in GitHub Desktop.
Function to get Dictionary from a class Object in Swift 2.0
func getDict(object : Any) -> [String:Any] {
var dict : [String:Any] = [:]
let miror = Mirror.init(reflecting: object)
for (_,attr) in miror.children.enumerate() {
if let _ = (Mirror.init(reflecting: attr.value)).displayStyle {
dict[attr.label!] = getDict(attr.value)
}
else {
dict[attr.label!] = attr.value
}
}
return dict
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment