Created
October 17, 2019 06:14
-
-
Save lalkrishna/8764263eecd72ac9dcdc7246fc313958 to your computer and use it in GitHub Desktop.
Extension for CustomStringConvertible to print All properties of a class
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
extension CustomStringConvertible { | |
var description: String { | |
var description: String = "\(type(of: self))(" | |
let selfMirror = Mirror(reflecting: self) | |
if let superclassMirror = selfMirror.superclassMirror { | |
for child in superclassMirror.children { | |
if let propertyName = child.label { | |
description += "Super.\(propertyName): \(child.value), " | |
} | |
} | |
} | |
for child in selfMirror.children { | |
if let propertyName = child.label { | |
description += "\(propertyName): \(child.value), " | |
} | |
} | |
description += "<\(Unmanaged.passUnretained(self as AnyObject).toOpaque())>)" | |
return description | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment