Override description or stringValue in cocoa?

I want to have a descriptive string for an object in Cocoa. I am thinking about the exception of the description method or the stringValue method. Which is preferable and why? The only thing I could find is here , indicating

You are not recommended to describe the description.

Is this really what you would suggest? Any other preferred override point?

+5
source share
4 answers

description - the path that he called to represent the string representation of the object.

- (NSString*)description
{
    return [NSString stringWithFormat:@"%@, %@; %@", a, b, c];
}

I believe that the proposed book of Hillegass also.

+5
source

description , . , Tom Duckering , .

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ <%p>", NSStringFromClass([self class]), self];
}
+7

, stringValue - - , . description stringValue , .

, stringValue (., , NSControl), description , .

+4

[NSObject debugDescription], . , "print to console" . NSLog.

debugDescription description, . .

- , . , , . , .

I have a debugging category for UIView that unloads every attribute I could think of. If I come across an unpleasant bug, I just turn on the category, and then I will see everything about each view right in the debugger console.

+2
source

All Articles