Created
September 18, 2015 13:18
-
-
Save rizumita/ed0e1bac3b72e31a107d to your computer and use it in GitHub Desktop.
Get value of property of class or struct by key as string
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 get<T>(sv: T, key: String) -> Any? { | |
let mirror = Mirror(reflecting: sv) | |
for (name, value) in mirror.children where name == key { | |
return value | |
} | |
return nil | |
} | |
get(s, key: "a") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment