Skip to content

Instantly share code, notes, and snippets.

@ManWithBear
Created November 20, 2016 17:42
Show Gist options
  • Save ManWithBear/8ef8a005c6e0bce216335f7b414b8915 to your computer and use it in GitHub Desktop.
Save ManWithBear/8ef8a005c6e0bce216335f7b414b8915 to your computer and use it in GitHub Desktop.
Extension to CustomStringConvertible for default description providing using reflection.
extension CustomStringConvertible {
var description : String {
var description: String = ""
if self is AnyObject {
description = "***** \(self.dynamicType) - <\(unsafeAddressOf((self as! AnyObject)))>***** \n"
} else {
description = "***** \(self.dynamicType) *****\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