Created
July 14, 2016 22:25
-
-
Save leoniralves/c93a667386805e4fcef9c6119c597d6b to your computer and use it in GitHub Desktop.
Get Properties Swift
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
struct Person { | |
let name: String | |
let lastname: String | |
} | |
class Reflection { | |
func printProperties(mirror: _MirrorType) { | |
for i in 0..<mirror.count { | |
let (name, childMirror) = mirror[i] | |
let value = childMirror.value | |
let type = childMirror.valueType | |
print("\(name) \(value) \(type)") | |
} | |
} | |
func getProperties() { | |
let john = Person(name: "John", lastname: "Levi") | |
let mirror = _reflect(john) | |
printProperties(mirror) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment