Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save olgusirman/f9c0e625d5c91a5c964290f01a8d80c3 to your computer and use it in GitHub Desktop.
Save olgusirman/f9c0e625d5c91a5c964290f01a8d80c3 to your computer and use it in GitHub Desktop.
Description extension for CustomStringConvertible protocol, usage for especially print objects
extension CustomStringConvertible {
var description : String {
var description: String = ""
description = "***** \(type(of: self)) *****\n"
let selfMirror = Mirror(reflecting: self)
for child in selfMirror.children {
if let propertyName = child.label {
description += "\(propertyName): \(child.value)\n"
}
}
return description
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment