Reputation: 5929
Rather than see a list of my custom objects' addresses in the variable view of the Xcode debugger, can I do something to display one of their properties, or my own description for the class instead?
In C#/Visual Studio this can be done by overriding ToString, so I tried overriding Description but it did not work:
-(NSString *)description
{
std::string fieldName = *(self->FieldName);
return [NSString stringWithFormat:@"<FieldName: %@>",
toNS(fieldName)];
}
Upvotes: 1
Views: 321
Reputation: 11918
Not 100% the same, but, have your class conform to CustomDebugStringConvertible
and provide a debugDescription
. Then when you see your objects in the debug area, right click on one and hit 'print description'. Or click on one and hit the 'quick look' icon below it in the debug area. You'll see the following printout in the console:
▿ my debugged object!
- title : "name1"
You can also view properties in the debug area by clicking the disclosure triangle next to each object in the list.
Usage:
struct CustomObject: CustomDebugStringConvertible {
var title: String
var debugDescription: String {
return "my debugged object!"
}
}
Upvotes: 1