Last active
December 29, 2015 19:17
-
-
Save harishgonnabattula/87f76ccc1ae86e64b41d to your computer and use it in GitHub Desktop.
Function to get Dictionary from a class Object in Swift 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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