In Objective-C, one can add a description
method to their class to aid in debugging:
@implementation MyClass
- (NSString *)description
{
ret
The answers relating to CustomStringConvertible
are the way to go. Personally, to keep the class (or struct) definition as clean as possible, I would also separate out the description code into a separate extension:
class foo {
// Just the basic foo class stuff.
var bar = "Humbug!"
}
extension foo: CustomStringConvertible {
var description: String {
return bar
}
}
let xmas = foo()
print(xmas) // Prints "Humbug!"