Looking for a Swift equivalent of Cocoa\'s description
, I found the following protocols in Swift: Printable
and DebugPrintable
.
I believe the main difference is the property that's used to print. Printable
has description
and DebugPrintable
has debugDescription
:
https://stackoverflow.com/a/24254220/887210
https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/SwiftStandardLibraryReference/Printable.html#//apple_ref/doc/uid/TP40014608-CH11-SW1
Edit:
Apparently print() and println() don't work properly with Printable and DebugPrintable:
struct TestPrintable : Printable {
var description: String { return "Testing Printable" }
}
struct TestDebugPrintable : DebugPrintable {
var debugDescription: String { return "Testing DebugPrintable" }
}
println(TestPrintable()) // -> "__lldb_expr_42.TestPrintable"
println(TestDebugPrintable()) // -> "__lldb_expr_42.TestDebugPrintable"
More information about this:
http://vperi.com/2014/06/04/textual-representation-for-classes-in-swift/