Last active
April 21, 2016 09:03
-
-
Save mattcomi/33e6817068a9fffcd8d1ef3ddf0df16e to your computer and use it in GitHub Desktop.
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
public protocol ReflectedStringConvertible : CustomStringConvertible { } | |
extension ReflectedStringConvertible { | |
public var description: String { | |
let mirror = Mirror(reflecting: self) | |
var str = "\(mirror.subjectType)(" | |
var first = true | |
for (label, value) in mirror.children { | |
if let label = label { | |
if first { | |
first = false | |
} else { | |
str += ", " | |
} | |
str += label | |
str += ": " | |
str += "\(value)" | |
} | |
} | |
str += ")" | |
return str | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been using something similar and it's been very helpful. You could simplify your implementation like so: