Skip to content

Instantly share code, notes, and snippets.

@leoniralves
Created July 14, 2016 22:25
Show Gist options
  • Save leoniralves/c93a667386805e4fcef9c6119c597d6b to your computer and use it in GitHub Desktop.
Save leoniralves/c93a667386805e4fcef9c6119c597d6b to your computer and use it in GitHub Desktop.
Get Properties Swift
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