Created
November 20, 2016 17:42
-
-
Save ManWithBear/8ef8a005c6e0bce216335f7b414b8915 to your computer and use it in GitHub Desktop.
Extension to CustomStringConvertible for default description providing using reflection.
This file contains hidden or 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 = "" | |
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