Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FirstClass {
- var name = ""
- var last_name = ""
- var age = 0
- var other = "abc"
- func listPropertiesWithValues(reflect: Mirror? = nil) {
- let mirror = reflect ?? Mirror(reflecting: self)
- if mirror.superclassMirror != nil {
- self.listPropertiesWithValues(reflect: mirror.superclassMirror)
- }
- for (index, attr) in mirror.children.enumerated() {
- if let property_name = attr.label {
- //You can represent the results however you want here!!!
- print("\(mirror.description) \(index): \(property_name) = \(attr.value)")
- }
- }
- }
- }
- class SecondClass: FirstClass {
- var yetAnother = "YetAnother"
- }
- var second = SecondClass()
- second.name = "Name"
- second.last_name = "Last Name"
- second.age = 20
- second.listPropertiesWithValues()
Add Comment
Please, Sign In to add comment