Created
July 10, 2019 15:27
-
-
Save olgusirman/f9c0e625d5c91a5c964290f01a8d80c3 to your computer and use it in GitHub Desktop.
Description extension for CustomStringConvertible protocol, usage for especially print objects
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 = "" | |
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