Skip to content

Instantly share code, notes, and snippets.

@khramtsoff
Last active January 3, 2024 06:01
Show Gist options
  • Save khramtsoff/ad84ba1b8a2e927c7b19aed5c36d5750 to your computer and use it in GitHub Desktop.
Save khramtsoff/ad84ba1b8a2e927c7b19aed5c36d5750 to your computer and use it in GitHub Desktop.
import Foundation
extension CustomStringConvertible {
var description: String {
var description: String = "\(type(of: self))("
let selfMirror = Mirror(reflecting: self)
for child in selfMirror.children {
if let propertyName = child.label {
description += "\(propertyName): \(child.value), "
}
}
description += "<\(Unmanaged.passUnretained(self as AnyObject).toOpaque())>)"
return description
}
}
class Person: CustomStringConvertible {
let name: String
let age: Int
init (name: String, age: Int) {
self.name = name
self.age = age
}
}
let alex = Person(name: "Alex", age: 20)
print(alex) // Person(name: Alex, age: 20, <0x000060c000058d20>)
@lalkrishna
Copy link

Thanks for the gist.

@tciuro
Copy link

tciuro commented May 5, 2020

+1 👍🏻

@AminPlusPlus
Copy link

@khramtsoff any thoughts ?

Screen Shot 2021-10-19 at 6 30 49 PM

Thanks

@tciuro
Copy link

tciuro commented Nov 21, 2021

Works fine for me (tried with the latest Version 13.2 beta 2 (13C5081f).)

Screen Shot 2021-11-21 at 10 56 43

Can you produce sample code to repro the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment